multiple scripts in parallel execution, trading once per script

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #150175 quote
    jpuentes
    Participant
    New

    Hi everyone, I was tried differents solutions posted in the forum, but none works in this context.

    I have 2 strategy scripts, script 1 running for ticket AAA, and script 2 running for ticket BBB (both in timeframe 1 second).

    I need these scripts running at the same time and with the restriction of only one trading for script, so in this context will have 2 trading as max.

    First try: using the reserved word ONCE but the script never starts.

    ONCE operationLaunched = 0 
    
    if operationLaunched = 0 then 
    	buy 10 shares at market 
    	SET STOP %LOSS 1 
    	SET TARGET %PROFIT 1
    	operationLaunched = 1 
    endif
    
    ONCE operationLaunched = 0 
    
    if operationLaunched = 0 then 
    	buy 10 shares at market 
    	SET STOP %LOSS 1 
    	SET TARGET %PROFIT 1
    	operationLaunched = 1 
    endif
    

    Second try, using the solution posted by Nicolas (https://www.prorealcode.com/topic/only-open-1-trade/), instead of 10, using 8*60*60 (8h x 60 sec x 60 sec)

    if barindex-tradeindex >=10 and myCondition then 
     buy 1 contract at market 
    endif

    But the problem with this approach is that if script 1 launchs the operation first, script 2 never start in the same day.

    I also try to get the Date, and other feasible variables, but with the same result.

    Thanks in advance, for any suggestion.

    #150181 quote
    robertogozzi
    Moderator
    Master

    Replace line 1 with these lines (sometimes ONCE behaves weirdly):

    IF strategyprofit = 0 AND Not OnMarket THEN
       operationLaunched = 0
    ENDIF
    jpuentes thanked this post
    #150184 quote
    jpuentes
    Participant
    New

    Roberto, thanks a lot for the fast answer !

    So, with this implementation I suppose that both scripts may stay on market at the same time, isn’t? Because OnMarket it’s true only in the scope of the script, and not return a global position of other scripts.

    Tonight I will try your solution. Thank you very much !!

    #150197 quote
    robertogozzi
    Moderator
    Master

    Yes, separate strategies are indipendent of one another. Each one of them doesn’t know about the existance of the others, even if on the same instrument and TF. They can even open positions in different directions.

    #150320 quote
    jpuentes
    Participant
    New

    Tested and it works fine !!

    Thank you very much for your help.

    Have a good day !

    robertogozzi thanked this post
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

multiple scripts in parallel execution, trading once per script


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
jpuentes @jpuentes Participant
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by jpuentes
5 years, 3 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/11/2020
Status: Active
Attachments: No files
Logo Logo
Loading...