Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Open a Trade on the same Candle

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

    Open a Trade on the same Candle

    Hello: I have written a code. It's a code where the main instrument takes a trade and the secondary instrument takes an opposite trade, simultaneously. I wanted the system to start trading on a 30-minute chart at 3:00 PM and stop trading at 11:00 PM. The code does that. Basically, it opens a position on the main instrument (LONG) if the previous candle is bullish and SHORTS the secondary instrument at the same time. Both trades exit at the start of the next candle. This is a hypothetical scenario:

    1. Previous Candle Bullish: The main instrument go LONG and the secondary instrument go SHORT at the start of the candle 3:30 PM
    2. Both positions exit at the start of the next candle. 4:00 PM
    3. Previous Candle Bearish: The main instrument go SHORT and the secondary instrument go LONG at the start of the candle 4:30 PM
    4. Both positions exit at the start of the next candle. 5:00 PM
    5. Previous Candle Bearish: The main instrument go SHORT and the secondary instrument go LONG at the start of the candle 5:30 PM
    6. Both positions exit at the start of the next candle. 6:00 PM

    So this is what it is doing: Enter trade at 3:30, exit positions at 4:00, Enter trade at 4:30, exit positions at 5:00, Enter trade at 5:30, exit positions at 6:00

    WHAT I WANT IS:

    I want the system to take another trade based on the logic when both positions exit at the start of the candle. Here is what I want it to look:

    1. Previous Candle Bullish: The main instrument go LONG and the secondary instrument go SHORT at the start of the candle 3:30 PM
    2. Both positions exit at the start of the next candle. 4:00 PM, THEN the system checks the previous bar again and takes the trade at 4:00 PM on both instruments on the same candle.
    3. Both Positions exit at 4:30. After this the system again checks thecandle, and The main instrument go SHORT and the secondary instrument go LONG at the start of the candle 4:30 PM (after reviwing the last candle)
    4. Both positions exit at the start of the next candle. 5:00 PM THEN the system checks the previous bar again and takes the trade at 5:00 PM on both instruments on the same candle
    AND SO ON ...

    However, I can't open a trade on the same candle. (Cant make the system to trade again after the exit of the previous position at the start of the candle.)

    Attached are the code and the chart that I am working on

    NEED HELP!

    Attached Files
    Last edited by cranky; 10-10-2023, 12:02 PM.

    #2
    Hello cranky,

    Thank you for your post.

    I see you have calculate set to Calculate.OnBarClose. You may need to consider which actions you would like to occur on the close of a bar vs. which actions you would like to be evaluated on each tick or on price change. We have an example of separating logic to occur on bar close vs. on each tick here:
    Another item to keep in mind is that with the managed approach, Entry() methods reverse a position automatically. For example, if you are in a long position for 1 contract and call EnterShort(), this results in an order to close the long position as well as an order to enter into the short position. You will likely need to set up your conditions to check if there is already a position in the desired direction based on whether a candle is bullish or bearish, and if it is in the opposite direction then you can call an entry method to reverse the position without having to call an exit method. This is noted in the key points on the page for the managed approach here:
    Please let us know if we may be of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    56 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    133 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    73 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 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