Applystop - stopModeRisk logic

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:

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:

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(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.

When posting the formula, please make sure that you use Code Tags (using </> code button) as explained here: How to use this site.

Using code button

Code tags are required so formulas can be properly displayed and copied without errors.

Everything you need to know about risk mode in ApplyStop is written in the Knowledge Base article:

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.