How to open immediately a position

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #62246 quote
    Lorenzo47
    Participant
    Average

    Hello everyone,

    I work on a very simple scalping code based on Parabolic SAR, the key of my strategy is to be very reactive once this indicator changes. (For information I’m on 1 minutes periods)

    Is it possible to open a position at the exact moment when the requested condition realizes (without waiting for the end of the current period) ? I understand that in my code, I always refer to a close which forces the algorithm to wait until the current candle closes. I’d like to know if it’s possible, just as the Stop Loss and Target Profit do, to open a position exactly when the condition happens.

    To make my strategy works I need to open a position exactly when my SAR indicator hits the market price.

    Here’s the problematic line :

    I know that “high” means that we need to wait until the end of the period for closure, is there any solution to open my position when the SAR crosses under, or “hit the price” ?

    Attached, how it impacts the chart on BackTest : my position is opened one candle too late.

    If anyone can help me with this, it would be amazing of you!

    Thanks a lot, looking forward to get your advices 🙂

    SAR-1.jpeg SAR-1.jpeg
    #62253 quote
    Eric
    Participant
    Master

    try this  https://www.prorealcode.com/topic/activate-a-trade/#post-60660

    change highest high to SAR instead (or lowest for sell)

    #62260 quote
    Nicolas
    Keymaster
    Master

    You can put pending orders on Sar levels, so they can triggered anytime between 2 bars.

    Lorenzo47 thanked this post
    #62287 quote
    Lorenzo47
    Participant
    Average

    Thanks Eric but I don’t think it’s going to help.. And by putting a stop I have one chance out of two to get the position at the wrong moment, for a scalping strategy I’m not sure it’s the best but thank you anyways

    #62288 quote
    Lorenzo47
    Participant
    Average

    Nicolas, Pending orders ? Very interesting, I did not know about this, could you explain me how it works and how to set one in my code to try if it works ?

    #62429 quote
    Nicolas
    Keymaster
    Master

    Pending STOP ORDERS:

    mysar = SAR[0.02,0.02,0.2]
    
    sellshort at mysar stop

    Each new candle, a new conditional SELLSHORT order will be placed at the exact SAR price. This order will take place in the broker’s order book and could be triggered if the price breach its level, even between 2 candlesticks.

    Lorenzo47 thanked this post
    #62436 quote
    Lorenzo47
    Participant
    Average

    Alright, thank you so much. I’m going to try this out and hopefully it will help! Anyways, as I understood there is no other way to do so far, so I will need to deal with that “hole” and adapt my strategy… Hopefully we will get soon a way to execute the calculation at each ticks no matter how big are the periods. It could help me a lot! 🙂 Thank you for your time

    #62466 quote
    Lorenzo47
    Participant
    Average

    Pending STOP ORDERS:

    Each new candle, a new conditional SELLSHORT order will be placed at the exact SAR price. This order will take place in the broker’s order book and could be triggered if the price breach its level, even between 2 candlesticks.

    I tried this but I can’t get the result I was expecting. Actually the algorithm takes a lot of positions at the wrong time (never when “the price hits the SAR point”). I guess it doesn’t put the stop order on the “SAR point” but why I can’t figure it out.. Here’s the “test” code I tried, maybe it’s something very obvious but I really can’t see it.

     

    // Indicators Settings 
    pSAR = SAR[0.02,0.02,0.2]
    
    //  Opening buy conditions
    
    BUY 1 CONTRACTS AT pSAR STOP
    
    // Opening sellshort conditons 
    
    SELLSHORT 1 CONTRACTS AT pSAR STOP
    
    //Stops and Targets
    SET STOP pLOSS SL
    SET TARGET pPROFIT TP
    SET STOP pTRAILING ST
    #63107 quote
    Nicolas
    Keymaster
    Master

    Are the SAR settings of the strategy the same as the one of the indicator displayed on your chart? (0.02,0.02,0.2)

    #63128 quote
    Eric
    Participant
    Master

    dont forget to adjust for the spread

    its always bid and ask that trigger the trade when using stoporder

    and sar is based on price only

    #63894 quote
    Lorenzo47
    Participant
    Average

    Nicolas, yes the SAR settings are exactly the same.

    Eric, thanks and yes I’ve obviously done that.

    The pending orders are working not bad, it needs some adjustments (as every strategy as guess) due to the big unknown.. But so far I think that’s the best solution to it. And btw, just to share it with you guys, I forgot to enable “tick per tick mode” which cost me some mistakes on my stops trailing. Shame on me!

    PS : sorry for not having replying, I was out of the country for business

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

How to open immediately a position


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Lorenzo47 @lorenzo47 Participant
Summary

This topic contains 10 replies,
has 3 voices, and was last updated by Lorenzo47
8 years ago.

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