I need some direction for the following:
Currently I am using a trailing stop strategy / study with multiple duplicates (in a single study with a suffix added to the variables and whatnot) for backtesting.
I would like to take a code similar to this:
then have each of those loop through the code for profitLoss without having to have 1000 lines of code...
I am having some technical difficulties figuring out how to achieve this... any help would be appreciated.
Currently I am using a trailing stop strategy / study with multiple duplicates (in a single study with a suffix added to the variables and whatnot) for backtesting.
I would like to take a code similar to this:
Code:
def profitLoss;
if (!isOrder or orderPrice[1] == 0) {
profitLoss = 0;
} else if ((isOrder and isLong[1]) and (SellSig or BuyStpSig)) {
profitLoss = close - orderPrice[1];
} else if ((isOrder and isShort[1]) and (BuySig or SellStpSig)) {
profitLoss = orderPrice[1] - close;
} else {
profitLoss = 0;
}
#And instead of copy pasting it ten times create a list for each variable:
def sellsignallist = {SellSig_1, SellSig_2, SellSig_3, SellSig_4}
etc...
then have each of those loop through the code for profitLoss without having to have 1000 lines of code...
I am having some technical difficulties figuring out how to achieve this... any help would be appreciated.