im trying to write a script with follow logic
when MA1 cross over MA2 - put a buy order
when MA1 cross under MA2 - put a sell order (at moment no sellshort)
once there is an open position (ie buy order executed), i want to set a profit target and stop lose based on percentage as well
for example - when it makes a 20% profit of the value in the buy order, then sell
when it makes a 10% lose of the value in the buy order, then also sell
i had written the first part of the MA1 cross MA2 but no clue how to write the second part (set profit target n stop lose). will much appreciate if you guys can advice!
fyi here is the script i wrote for the first part
Code: Select all
inputs: Price( Close ), FastLength( 9 ), SlowLength( 18 );
variables: var0( 0 ), var1( 0 );
var0 = AverageFC( Price, FastLength ) ;
var1 = AverageFC( Price, SlowLength ) ;
condition11 = CurrentBar > 1 and var0 crosses over var1 ;
if condition11 then
Buy ( "MA2CrossLE" ) next bar at market ;
condition12 = CurrentBar > 1 and var0 crosses below var1 ;
if condition12 then
sell ( "MA2CrossSE" ) next bar at market ;