Save Study value at the specific point on chart

Daco4892

New member
Save study (like ATR) value at the specific point on chart. Than don't change that value until different picked point on chart.
In example below I was trying to load "buyATR" with value of ATR when "buy" signal. I wanted to retain the value until next "buy" signal and at that point change to the new ATR value. It seems fairly simple but I cannot get it. Please someone help.

Code:
input ShortMALength = 50;
input LongMALength = 200;

def ShortMA = SimpleMovingAvg(length = ShortMALength);
def LongMA = SimpleMovingAvg(length = LongMALength);

def buy = if ShortMA[1] < LongMA[1] and ShortMA > LongMA then 1 else 0;
def sell = if ShortMA[1] > LongMA[1] and ShortMA < LongMA then 1 else 0;

def buyATR = if buy then ATR() else 0;

AddOrder(OrderType.BUY_AUTO, buy == 1);
AddOrder(OrderType.SELL_AUTO, sell == 1);
 

Similar threads

Top