Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem me running the same strategy in two different time frames on different graphs

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Problem me running the same strategy in two different time frames on different graphs


    I need help to solve this problem,
    I have a strategy that I am running in 2 different times, 1 minute and 2 minutes at the same time, I tell you that if it is 1:00 pm and you have an open operation, you should close it and cancel all pending orders.

    The problem is the following:

    For example, we have an order with 10 long, at 1:00 pm, when the program runs, in a time frame of 1 minute I see the 10 positions and it takes me out of the position, and at the same time the time frame of 2 minutes comes and it takes me out too. of the long, it remained in a position of 10 In short, and the Cycle is repeated, falling in an endless loop.​




    private void StopStrategy(){

    // Verificar si ya estamos planos o ya estamos cerrando una posición
    if (isFlat || isClosingPosition)
    {
    return;
    }

    isClosingPosition = true;

    // Detener procesamiento y cancelar órdenes
    haltProcessing = true;
    CancelAll();

    if (PositionAccount.MarketPosition == MarketPosition.Long && isClosingPosition){

    SubmitOrderUnmanaged(1, OrderAction.SellShort, OrderType.Market,PositionAccount.Quantity, 0,0,"","Cierre por Horario Bull");
    isClosingPosition = false;
    }

    else if (PositionAccount.MarketPosition == MarketPosition.Short && isClosingPosition){

    SubmitOrderUnmanaged(1, OrderAction.BuyToCover, OrderType.Market,PositionAccount.Quantity, 0, 0,"","Cierre por Horario Bear");
    isClosingPosition = false;
    }
    }​
    Attached Files

    #2
    Hello HGTrader,

    I am not certain I follow what the problem is here. Are you saying that the two strategies are submitting conflicting actions?

    Comment


      #3
      The problem is that it never remains flat and enters a loop, because it repeats the operation in both temporalities.

      What I would like to do is tell you if you have a position of 10 contracts long, it is 1:00 pm, exit the position and go Flat.

      What is the strategy doing? It leaves the position of 10 contracts in the time frame of 1 minute and at the same time it reads that we have 10 positions in the time frame of 2 minutes and executes another sale to exit the long position of 10 that no longer exists, creating a short position.

      and never that flat

      Note: in playback it works perfectly, but when I am in real connected with a Ritmic account it presents the loop​

      Comment


        #4
        Hello HGTrader,

        If your logic is not working as expected you would need to debug it to see why that is happening. You can use prints as one means to output what the strategy is doing.

        It is also suggested that you combine multiple strategies into one strategy so it can have a full picture of what it is doing. When you use more than one strategy on the same account they won't have any communication so it is possible for them to become out of sync or conflict with each other.

        Comment


          #5


          What I didn't want was to add a new temporality to the strategy, I thought that running the same strategy in two different temporalities and with the same account would work perfectly.

          Question: Because in playback it works perfectly but not in real?​

          Comment


            #6
            Hello HGTrader,

            As I don't know what part of your logic is having a problem I really couldn't say what it may work in playback but not realtime. In general running two strategies on the same instrument and account will conflict with each other because they run independently and can't talk to each other. While you can monitor the account position that does not prevent each strategy from working independently for its logic. If your logic is allowing for that situation then you would have to debug why that is happening when you run it in realtime. You can use a demo account of a sim account to test it in realtime after adding prints. You would need to output the values for your conditions to trade to see why they are working in that way when you run it.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            54 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            130 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            71 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            44 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            49 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X