JSParticipant
Senior
Hi,
I’ve tried your code, including the timeframes, and I think it works as expected…
(PRT+IB)
Hi PeterST,
I’m struggling to get it working. Can you help me with the correct modification?
This is the last test I did:
// LONG open dates
$myDateL[1] = 20230316
$myDateL[2] = 20230328
$myDateL[3] = 20230411
$myDateL[4] = 20230424
// LONG exit dates
$myExitL[1] = 20230321
$myExitL[2] = 20230403
$myExitL[3] = 20230417
$myExitL[4] = 20230428
LastElementL = 4
SLpercent = 2 //2% stop loss
//
IF Not OnMarket THEN
FOR i = 1 TO (LastElementL)
//LONG trades
IF i <= LastElementL THEN
IF Date = $myDateL[i] THEN
BUY 1 CONTRACT AT MARKET
SET STOP %LOSS SLpercent
break
ENDIF
ENDIF
// exit LONG trades
IF LongOnMarket THEN
FOR i = 1 TO LastElementL
IF Date = $myExitL[i] THEN
SELL AT MARKET
break
ENDIF
NEXT
ENDIF
Thanks again for your input.
Thanks for testing the code. We get different results.
I have PRT+IG, maybe that makes the difference.
JSParticipant
Senior
Hi,
Try this one…
// LONG open dates
$myDateL[1] = 20230316
$myDateL[2] = 20230328
$myDateL[3] = 20230411
$myDateL[4] = 20230424
// LONG exit dates
$myExitL[1] = 20230321
$myExitL[2] = 20230403
$myExitL[3] = 20230417
$myExitL[4] = 20230428
LastElementL = 4
SLpercent = 2 //2% stop loss
//
IF Not OnMarket Then
FOR i = 1 TO (LastElementL) // Enter LONG Trades
IF Date = $myDateL[i] THEN
Buy 1 Contract at Market
Set STOP %LOSS SLpercent
Break
EndIf
Next
EndIf
// Exit LONG Trades
IF LongOnMarket THEN
FOR i = 1 TO LastElementL
IF Date = $myExitL[i] THEN
SELL AT MARKET
Break
EndIf
Next
EndIf
Hi PeterST,
I’m struggling to get it working. Can you help me with the correct modification?
This is the last test I did:
Hello Fredrik,
Can you please tell once again what exactly is not working with “the last test you did” ?
Also, when you receive an error message, then it is good to know what the message is. 😉
Peter
Hi again. it is solved.
Will run one LONG test and one SHORT test separately, so the orders in the code (same day orders, different directions and close/open) does not cancel out each other. 🙂