Hi All,
Was wondering if someone can take a look at my code and tell me why my 'movediff' line isn't counting the difference between the exit and entries (the chart bubbles). My goal is to combine the historical difference in the entry and exits then divide by the number of times the trade triggered so that I can get the average move per trade. I've been at this all day and im stumped....
Was wondering if someone can take a look at my code and tell me why my 'movediff' line isn't counting the difference between the exit and entries (the chart bubbles). My goal is to combine the historical difference in the entry and exits then divide by the number of times the trade triggered so that I can get the average move per trade. I've been at this all day and im stumped....
Code:
def h = high;
def l = low;
def o = open;
def c = close;
def insidebar = (H <= H[1] and L >= L[1]);
def twodown = H <= H[1] and L < L[1];
def Cross_Up = H > H[1];
def Mag_UP = H >= H[2];
# Strat Combos
def Two_One_UP = twodown[2] and insidebar[1] and Cross_Up ;
def bn = barnumber();
def trigger = Two_One_UP;
def triggercount = if trigger then triggercount[1] + 1 else triggercount[1];
def on = if trigger then on[1] * 0 + 1 else if on[1] ==1 and low <low[1] then on[1]-1 else on[1];
def entry = if on == 1 and on[1] == 0 then high[1] else double.nan;
def exit = if on[1] == 1 and on == 0 then low[1] else double.nan;
def entryprice = if trigger and !exit then high[1] else entryprice[1];
def exitprice = if exit then low[1] else exitprice[1];
def movediff = if on[1] ==1 and on ==0 then movediff[1] + exitprice-entryprice else movediff[1];
def avgmovediff = movediff/triggercount;
addlabel(yes, movediff, color.white);
addchartbubble(entry,high[1], high[1], color.cyan);
addchartbubble(exit,low[1], low[1], color.magenta);