Stock Portfolio Organizer
The ultimate porfolio management solution.
Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
WiseTrader Toolbox
#1 Selling Amibroker Plugin featuring:
Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
jessilevinmore for Amibroker (AFL)
Copy & Paste Friendly
Back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 | _SECTION_BEGIN ( "jesselevenmore" ); //------------------------------------------------------------------------------ // Formula Name : Project Freedom - Jesse Livermore Secret Market Key // Author : KH Tang // Date Updated : 30 Apr 2007 // Origin : Personal Study and Understanding of Livermore's work // Version : 1.0 // Blog : http://blessedfool.gaia.com/blog //------------------------------------------------------------------------------ /* //------------------------------------------------------------------------------ Program Overview This program classifies price action into the following states based upon rules his book - "How to Trade in Stocks" StateNo1 - Up Trend StateNo2 - Nat Rally StateNo3 - Sec Rally StateNo4 - Dn Trend StateNo5 - Nat React StateNo6 - Sec React State change is determined by a user specified threshold of price change. The program also determines a number of pivot points: UpTrendPP - Peak Up Trend Price NatRallyPP - Peak Nat Rally Price DnTrendPP - Bottom Dn Trend Price NatReactPP - Bottom Nat React Price This program may be used as a basis for a number of studies: - trend paint bars, - pivot price indicator lines - strategies (trend following AND/OR breakout/breakDn) For detailed explanation of the system Jesse Livermore Orginal Work. Note: Livermore's system used a threshold of 6 points for stocks priced over $30. For modern Market, due to different markets has wide range of prices. The threshold price is set in Percentage...(default 10%) //------------------------------------------------------------------------------ */ // General Graphic Control GraphXSpace = 15; SetChartBkGradientFill ( ParamColor ( "BgTop" , colorSkyblue ), ParamColor ( "BgBottom" , colorWhite ), ParamColor ( "titleblock" , colorWhite )); ThresholdPercentValue = Param ( "Threshold in Percent units" ,10,4,15,1); for ( i=0; i< BarCount ; i++ ) { if (i==0) { //Initialization //var: StateNo[i]=1; InUpTrend[i]= True ; InDnTrend[i]= False ; SecRally[i] = NatRally[i] = UpTrend[i] = Close [i]; SecReact[i] = NatReact[i] = DnTrend[i] = Close [i]; NatRallyReset[i]= True ; NatReactReset[i]= True ; UpTrendPP[i]= C [0]; NatRallyPP[i]= C [0]; NatReactPP[i]= C [0]; DnTrendPP[i]= C [0]; } //end; else //{Main} { //begin //{calc current Threshold if required} // Memory Refresh Manually... Work like refreshing the D-Ram. // This is the fastest trick to handle the issue with AMI-AFL. (KH Tang) // With this, one can program anything in a flowchart. :-) StateNo[i]=StateNo[i-1]; InUpTrend[i]=InUpTrend[i-1]; InDnTrend[i]=InDnTrend[i-1]; UpTrend[i] = UpTrend[i-1]; NatRally[i] = NatRally[i-1]; SecRally[i] = SecRally[i-1]; SecReact[i] = SecReact[i-1]; NatReact[i] = NatReact[i-1]; DnTrend[i] = DnTrend[i-1]; NatRallyReset[i]=NatRallyReset[i-1]; NatReactReset[i]=NatReactReset[i-1]; UpTrendPP[i]=UpTrendPP[i-1]; NatRallyPP[i]=NatRallyPP[i-1]; NatReactPP[i]=NatReactPP[i-1]; DnTrendPP[i]=DnTrendPP[i-1]; ThresholdPct[i]=ThresholdPercentValue[i]/100; //------------------------------------------------------------------------------ //111111111111111111111111111111111111111111111111111111111111111111111111111111 //------------------------------------------------------------------------------ //State No 1: In Up Trend Column if (StateNo[i-1]==1) // { //UpTrend Routine if ( C [i]>= C [i-1]) { //Price Move Up if ( C [i]>UpTrend[i]) { StateNo[i]=1; //Remain in UpTrend - 1111111111111111111111111111111 InUpTrend[i]= True ; InDnTrend[i]= False ; UpTrend[i]= C [i]; } } //End of Price Move Up else { //Price Move Dn if ((InDnTrend[i] AND C [i]<DnTrendPP[i]) OR //PivotPoint Check (InUpTrend[i] AND C [i]< UpTrend[i]/(1+2*ThresholdPct[i])) ) { //Drop to DnTrend StateNo[i]=6; //Dn Trend - 6666666666666666666666666666666666666666 InDnTrend[i]= True ; InUpTrend[i]= False ; DnTrend[i]= C [i]; UpTrendPP[i]=UpTrend[i]; } // End of Drop to DnTrend else { if ( C [i]<(UpTrend[i]/(1+ThresholdPct[i]))) { //Drop Below Current State React if (NatReactReset[i] OR C [i] < NatReact[i]) { //First Time or Below NatReact StateNo[i]=5; //Nat React - 55555555555555555555555555555555 NatReactReset[i]= False ; NatReact[i]= C [i]; UpTrendPP[i]=UpTrend[i]; } //End of First Time or Below NatReact else { //Drop to SecReact StateNo[i]=4; //SecReact - 444444444444444444444444444444444 SecReact[i]= C [i]; UpTrendPP[i]=UpTrend[i]; } //End of Drop to SecReact } } //End of Drop Below Current Price React } //End of Price Move Dn } //End of UpTrend Routine //------------------------------------------------------------------------------ //222222222222222222222222222222222222222222222222222222222222222222222222222222 //------------------------------------------------------------------------------ //State No 2: In Nat Rally Column else if (StateNo[i-1]==2) // { //NatRally Routine //NatRallyReset=False; if ( C [i]> C [i-1]) { //Price Move Up if ( (InUpTrend[i] AND C [i]>UpTrendPP[i]) OR (InDnTrend[i] AND C [i]> DnTrend[i]*(1+2*ThresholdPct[i])) ) { //Price move to UpTrend - 1111111111111111111111111111111111111111111 StateNo[i]=1; InUpTrend[i]= True ; InDnTrend[i]= False ; UpTrend[i]= C [i]; } //End of Price Move to UpTrend else { if ( C [i]>NatRally[i]) { //Price Continue to move to higher NatRally StateNo[i]=2; //Remain in NatRally - 222222222222222222222222222 NatRally[i]= C [i]; NatRallyReset[i]= False ; } //End of Price Continue to move to higher NatRally } } //End of Price Move Up else //of(C[i]>C[i-1]) { //Price Move Dn if ((InDnTrend[i] AND C [i]<DnTrendPP[i]) OR (InUpTrend[i] AND C [i]< UpTrend[i]/(1+2*ThresholdPct[i])) ) { //Drop to DnTrend StateNo[i]=6; //Dn Trend - 6666666666666666666666666666666666666666 InDnTrend[i]= True ; InUpTrend[i]= False ; DnTrend[i]= C [i]; NatRallyPP[i]=NatRally[i]; } // End of Drop to DnTrend else { if ( C [i]<(NatRally[i]/(1+ThresholdPct[i]))) { //Drop Below Current State React if (NatReactReset[i] OR C [i] < NatReact[i]) { //First Time or Below NatReact StateNo[i]=5; //Nat React - 55555555555555555555555555555555 NatReactReset[i]= False ; NatReact[i]= C [i]; NatRallyPP[i]=NatRally[i]; } //End of First Time or Below NatReact else { //Drop to SecReact StateNo[i]=4; //SecReact - 444444444444444444444444444444444 SecReact[i]= C [i]; NatRallyPP[i]=NatRally[i]; } //End of Drop to SecReact } } //End of Drop Below Current Price React } //End of Price Move Dn } //End of NatRally Routine //------------------------------------------------------------------------------ //333333333333333333333333333333333333333333333333333333333333333333333333333333 //------------------------------------------------------------------------------ //State No 3: In Sec Rally Column else if (StateNo[i-1]==3) // { //SecRally Routine if ( C [i]> C [i-1]) { //Price Move Up if ( (InUpTrend[i] AND C [i]>UpTrendPP[i]) OR (InDnTrend[i] AND C [i]> DnTrend[i]*(1+2*ThresholdPct[i])) ) { //Price move to UpTrend - 1111111111111111111111111111111111111111111 StateNo[i]=1; InUpTrend[i]= True ; InDnTrend[i]= False ; UpTrend[i]= C [i]; } //End of Price Move to UpTrend else { if ( C [i]>NatRally[i]) { //Price Continue to move to higher NatRally StateNo[i]=2; //Remain in NatRally - 222222222222222222222222222 NatRally[i]= C [i]; NatRallyReset[i]= False ; } //End of Price Continue to move to higher NatRally else { //Remain at SecRally State if ( C [i]>SecRally[i]) { //New Higher Sec Price - 3333333333333333333333333333333333333 StateNo[i]=3; //Remain in SecRally State SecRally[i]= C [i]; //Update new higher price } //End of New Higher Sec Price } //End of Remain at Sec State } } //End of Price Move Up else //of(C[i]>C[i-1]) { //Price Move Dn if ((InDnTrend[i] AND C [i]<DnTrendPP[i]) OR (InUpTrend[i] AND C [i]< UpTrend[i]/(1+2*ThresholdPct[i])) ) { //Drop to DnTrend StateNo[i]=6; //Dn Trend - 666666666666666666666666666666666666666 6 InDnTrend[i]= True ; InUpTrend[i]= False ; DnTrend[i]= C [i]; } // End of Drop to DnTrend else { if ( C [i]<(SecRally[i]/(1+ThresholdPct[i]))) { //Drop Below Current State React if ( C [i] < NatReact[i]) { //First Time or Below NatReact StateNo[i]=5; //Nat React - 55555555555555555555555555555555 NatReact[i]= C [i]; } //End of First Time or Below NatReact else { //Drop to SecReact StateNo[i]=4; //SecReact - 444444444444444444444444444444444 SecReact[i]= C [i]; } //End of Drop to SecReact } } //End of Drop Below Current Price React } //End of Price Move Dn } //End of SecRally Routine //------------------------------------------------------------------------------ //444444444444444444444444444444444444444444444444444444444444444444444444444444 //------------------------------------------------------------------------------ //State No 4: In Sec React Column //Note that these two state are sharing the same processing routine else if (StateNo[i-1]==4) // { //SecReact Routine if ( C [i]> C [i-1]) { //Price Move Up if ( (InUpTrend[i] AND C [i]>UpTrendPP[i]) OR (InDnTrend[i] AND C [i]> DnTrend[i]*(1+2*ThresholdPct[i])) ) { //Price move to UpTrend - 1111111111111111111111111111111111111111111 StateNo[i]=1; InUpTrend[i]= True ; InDnTrend[i]= False ; UpTrend[i]= C [i]; } //End of Price Move to UpTrend else { if ( C [i]>(SecReact[i]*(1+ThresholdPct[i]))) { //Raise Above Current State React if ( C [i]>NatRally[i]) { StateNo[i]=2; //Move to NatRally - 2222222222222222222222 NatRally[i]= C [i]; NatRallyReset[i]= False ; } else { //Raise to SeconaryRally StateNo[i]=3; //Raise to SecRally - 333333333333333333333 SecRally[i]= C [i]; } //End of Raise to SecRally } // End of Raise Above Current State React } } //End of Price Move Up else //of(C[i]>C[i-1]) { //Price Move Dn if ((InDnTrend[i] AND C [i]<DnTrendPP[i]) OR (InUpTrend[i] AND C [i]< UpTrend[i]/(1+2*ThresholdPct[i])) ) { //Drop to DnTrend StateNo[i]=6; //Dn Trend - 6666666666666666666666666666666666666666 InDnTrend[i]= True ; InUpTrend[i]= False ; DnTrend[i]= C [i]; } // End of Drop to DnTrend else { if ( C [i]<NatReact[i]) { //Raise Above NatReact StateNo[i]=5; //NatReact - 5555555555555555555555555555555555555 NatReact[i]= C [i]; } //Raise Above NatReact else { //Remain at SecReact if ( C [i]<SecReact[i]) { //Lower SecReact SecReact[i]= C [i]; } //End of Lower SecReact } //End of Remain at SecReact } } //End of Price Move Dn } //End of Sec React Routine //------------------------------------------------------------------------------ //555555555555555555555555555555555555555555555555555555555555555555555555555555 //------------------------------------------------------------------------------ //State No 5: In Nat React Column else if (StateNo[i-1]==5) // { //NatReact Routine //NatReactReset=False; if ( C [i]> C [i-1]) { //Price Move Up if ( (InUpTrend[i] AND C [i]>UpTrendPP[i]) OR (InDnTrend[i] AND C [i]> DnTrend[i]*(1+2*ThresholdPct[i])) ) { //Price move to UpTrend - 1111111111111111111111111111111111111111111 StateNo[i]=1; InUpTrend[i]= True ; InDnTrend[i]= False ; UpTrend[i]= C [i]; NatReactPP[i]=NatReact[i]; } //End of Price Move to UpTrend else { if ( C [i]>(NatReact[i]*(1+ThresholdPct[i]))) { //Raise Above Current State React if (NatRallyReset[i] OR C [i]>NatRally[i]) { StateNo[i]=2; //Move to NatRally - 2222222222222222222222 NatRallyReset[i]= False ; NatRally[i]= C [i]; NatReactPP[i]=NatReact[i]; } else { //Raise to SeconaryRally StateNo[i]=3; //Raise to SecRally - 333333333333333333333 SecRally[i]= C [i]; NatReactPP[i]=NatReact[i]; } //End of Raise to SecRally } // End of Raise Above Current State React } } //End of Price Move Up else //of(C[i]>C[i-1]) - Common with State 1 { //Price Move Dn if ((InDnTrend[i] AND C [i]<DnTrendPP[i]) OR (InUpTrend[i] AND C [i]< UpTrend[i]/(1+2*ThresholdPct[i])) ) { //Drop to DnTrend StateNo[i]=6; //Dn Trend - 6666666666666666666666666666666666666666 InDnTrend[i]= True ; InUpTrend[i]= False ; DnTrend[i]= C [i]; } // End of Drop to DnTrend else { if ( C [i]<NatReact[i]) { //Raise Above NatReact StateNo[i]=5; //NatReact - 5555555555555555555555555555555555555 NatReact[i]= C [i]; } //Raise Above NatReact } } //End of Price Move Dn } //End of NatReact Routine //------------------------------------------------------------------------------ //666666666666666666666666666666666666666666666666666666666666666666666666666666 //------------------------------------------------------------------------------ //State No 6: In Dn Trend Column else if (StateNo[i-1]==6) // // Must be in State No 6 { //DnTrend Routine if ( C [i]> C [i-1]) { //Price Move Up if ( (InUpTrend[i] AND C [i]>UpTrendPP[i]) OR (InDnTrend[i] AND C [i]> DnTrend[i]*(1+2*ThresholdPct[i])) ) { //Price move to UpTrend - 1111111111111111111111111111111111111111111 StateNo[i]=1; InUpTrend[i]= True ; InDnTrend[i]= False ; UpTrend[i]= C [i]; DnTrendPP[i]=DnTrend[i]; } //End of Price Move to UpTrend else { if ( C [i]>(DnTrend[i]*(1+ThresholdPct[i]))) { //Raise Above Current State React if (NatRallyReset[i] OR C [i]>NatRally[i]) { StateNo[i]=2; //Move to NatRally - 2222222222222222222222 NatRallyReset[i]= False ; NatRally[i]= C [i]; DnTrendPP[i]=DnTrend[i]; } else { //Raise to SeconaryRally StateNo[i]=3; //Raise to SecRally - 333333333333333333333 SecRally[i]= C [i]; DnTrendPP[i]=DnTrend[i]; } //End of Raise to SecRally } // End of Raise Above Current State React } } //End of Price Move Up else //of(C[i]>C[i-1]) - Common with State 1 { //Price Move Dn if ( C [i]<DnTrend[i]) { //Price move futher Dn StateNo[i]=6; //Dn Trend - 6666666666666666666666666666666666666666 InDnTrend[i]= True ; InUpTrend[i]= False ; DnTrend[i]= C [i]; } //End of Price move Futher Dn } //End of Price Move Dn } //End of DnTrend Routine //------------------------------------------------------------------------------ //Checking and Processing Parameters here... //Reset Value of Rally and React Values if needed // React Values become Obseleted Price moved to high up. Reset them. if (InUpTrend[i] AND NatReact[i] < UpTrend[i]/(1+2*ThresholdPct[i]) ) { NatReactReset[i]= True ; } // Rally Values become Obaseleted as Price move to low Dn. Reset them if (InDnTrend[i] AND NatRally[i] > DnTrend[i]*(1+2*ThresholdPct[i]) ) { NatRallyReset[i]= True ; } } //end; //{main} } //End of For i Loop! //Plotting Section - Just for testing //InUpTrend WeightNo= IIf (StateNo==1,5, // UpTrend IIf (InUpTrend AND StateNo==5,1, // and NatReact IIf (InUpTrend AND StateNo==2,4, // and NatRally IIf (InUpTrend AND StateNo==4,2, // and SecReact IIf (InUpTrend AND StateNo==3,3, // and SecRally IIf (StateNo==6,-5, // DownTrend IIf (InDnTrend AND StateNo==2,-1, // and NatRally IIf (InDnTrend AND StateNo==5,-4, // and NatReact IIf (InDnTrend AND StateNo==3,-2, // and SecRally -3 // and SecReact ))))))))); Plot (WeightNo, "Livermore Secret Market Key Stage Diagram" , IIf (WeightNo>0 AND WeightNo==5, colorGreen , IIf (WeightNo>0, colorBlue , IIf (WeightNo<0 AND WeightNo==-5, colorRed , colorPink ))), styleStaircase ); Plot (0, "" , colorBlack , styleNoLabel ); //End of Livermore Market Key Section _SECTION_END (); |