how to set protfit target and stop lose based on percentage

Questions about MultiCharts and user contributed studies.
davidlaw_mc
Posts: 5
Joined: Jul 08 2024
Has thanked: 3 times

Jul 09 2024

hi all,

warm greeting from a newbie here!

im trying to write a script with follow logic (simple one as a lesson 101 lol)

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

//

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 ;

User avatar
TJ
Posts: 7774
Joined: Aug 29 2006
Location: Global Citizen
Has thanked: 1036 times
Been thanked: 2233 times

Jul 10 2024

See posts #1 & #2
viewtopic.php?t=11713