I’m trying to refer to a price level as a Short trigger level which is the Low of a bar and which meets a specific condition (MACD cross over). As soon as the price falls through the Low of the bar that meets the MACD condition within the last 20 bars, sell short.
My code shorts at the Low of last bar and not at the trigger level.
Can anyone help, please.
Thank you
Code: Select all
Var: ShortTrig(0);
Var: TrigLow(0);
Var: TrigHigh(0);
Var: ShortCondition(0);
Var: LongCondition(0);
TrigLow = Low(0);
TrigHigh = High(0);
inputs: FastLength( 12 ), SlowLength( 26 ), MACDLength( 9 ) ;
variables: var0( 0 ), var1( 0 ), var2( 0 ) ;
var0 = MACD( Close, FastLength, SlowLength ) ;
var1 = XAverage( var0, MACDLength ) ;
var2 = var0 - var1 ;
condition1 = CurrentBar > 2 and var2 crosses over 0 ;
if condition1 then begin
TrigLow = Low(0);
end;
if countif(condition1,20)>= 1 then
SellShort next bar at TrigLow stop ;
if barssinceentry > 20 then buytocover next bar at market;