Hello
I am trying to prove the trail stops produced using the standard function APPLYSTOP as follows in a one liner in my beginner script:
ApplyStop( stopTypeTrailing , stopModeRisk, riskSize, 0, False, 0, daysDelay );
riskSize = optimize("stopRiskSize", 25, 20,45,5);
daysDelay = Optimize("stopDaysDelay", 2,2,40,6);
Using AFL to check the signals produced with the below works a lot of the time but not all; problem is I dont know the logic to use so I am second guessing; ie is the stop fired when close is less than the stop value (as calculated below) or some other rule?
I am looking at the above using values from EXPLORE to verify output:
//CALCULATION OF ASSUMED STOP WITHIN APPLYSTOP
priceAtBuy = ValueWhen( Buy, BuyPrice,1);
highsinceBuy = HighestSince( Buy, High);
stoplevel = priceAtBuy + ( highsinceBuy - priceAtBuy) * (100-riskSize)/100;
.. then second guessing the rules APPLYSTOP uses, eg close less than the stoplevel above. Something is missiing:
//TESTING
AddColumn((highsinceBuy-Close)/(highsinceBuy-priceAtBuy), "STOPP3",1.6);
//AddColumn((highsinceBuy-Max(Close,Open))/(highsinceBuy-priceAtBuy), "STOPP3",1.4);
AddColumn(((highsinceBuy-stoplevel)/(highsinceBuy-priceAtBuy)), "STOPP4",1.6);
AddColumn(highsinceBuy, "highsinceBuy",1.6);
AddColumn(Max(Close,Open), "max close/open",1.6);
AddColumn((highsinceBuy-priceAtBuy),"highsinceBuy-priceAtBuy",1.6);
AddColumn(priceAtBuy + ( highsinceBuy - priceAtBuy) * (100-riskSize)/100,"stop lvl",1.6);
In the above I am looking at the actual trailing loss % compared to the input 25%; if the loss is greater I assume an exit signal, however as above, this is not quite right.