Code problem with time conditions

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #62809 quote
    Spatial
    Participant
    Junior

    Hi I got 2 questions about my code.

    1. I want to take entry between 17:20-17:30 if my signal i active, but it seems that the entry is in the next bar? It should be in the signal bar.

    2. I also want to do my exit between 17:20-17:30, is it possible to do a “noExitBeforeTime” and “noExitAfterTime”? The idea is to sell between 17:20-17:30 if the position is in profit. After 5 bars I will sell anyway.

    [attachment file=62810]

    CodeProblem-1.png CodeProblem-1.png
    #62834 quote
    robertogozzi
    Moderator
    Master

    ProOrder ALWAYS runs strategies when the signal bar closes and opens a trade, if conditions are met, afterwards, that’s why there’s one bar difference, though it may be just microseconds!  This is true as of the caurrent version, the new one in the works is said to behave differently.

    As for your 2nd question, to exit after n bars you may use the expression

    BarIndex - TradeIndex

    which returns the number of bars elapsed since the trade was started. If you want to add a condition to exit only if in profit you have to just check the current (closing) price and TradePrice as

    IF BARINDEX-TRADEINDEX(1)>5 AND Close-TRADEPRICE(1)>10 AND LongOnMarket THEN

    see line 15 at https://www.prorealcode.com/documentation/tradeprice/, where both condition are used to exit a Profitable trade after 5 bars have elapsed.

    Spatial thanked this post
    #62899 quote
    Spatial
    Participant
    Junior

    Thanks!

    So I will allways miss the GAP to the next bar? This will happen often since I will trade daily timeframe. I got the version 10.3.

    And the same will be in point number 2, if I want to sell on the bar when stockmarket close at 17:30, the sell will be next morning?

    #62918 quote
    Nicolas
    Keymaster
    Master

    So I will allways miss the GAP to the next bar? This will happen often since I will trade daily timeframe. I got the version 10.3. And the same will be in point number 2, if I want to sell on the bar when stockmarket close at 17:30, the sell will be next morning?

    Yes that’s how it behaves.

    #62940 quote
    GraHal
    Participant
    Master

    You could exit manually at 17:30 via the IG App on your phone then start your Daily TF Algo again later before you go to bed and before midnight?

    Ha … I just thought of another way … if you leave your PC / Laptop running it appears that you could set an Alert and an associated Trigger to sell / buy and then this will close your Algo. All external interference with an Algo will close it down!

    I’ve not tried about with date/ time so test it out and let us know how you get on?

    See attached
    GraHal

    Nicolas thanked this post
    Sp-1.jpg Sp-1.jpg
    #71195 quote
    Dymjohn
    Participant
    Senior

    Hi Thought my problem was related to this and so I added it here.

    I want to close a trade after 5 bars so wrote:

    if LongonMarket and (BarIndex-TradeIndex) < 4 then
    
    Trade = 1
    
    else
    
    Trade = 0
    
    //conditions to close trades
    
    etc etc Trade =0

    However this closes every subsequent trade on the first bar. I’ve tried a once Trade = 1 after the close the trade instruction doesn’t work either.

    Any help with this would be appreciated

    #71199 quote
    Dymjohn
    Participant
    Senior

    Found a solution

    c5 = (TradeIndex +5 = BarIndex)

    This will close if c5 is in the sell conditions for a long trade

    #71247 quote
    Vonasi
    Moderator
    Master

    I’m glad that you found your solution Dymjohn.

    Can I ask you to please use the ‘Insert PRT Code’ button in future posts as it makes everything much more readable for others. I’ve tidied up your posts here for you.

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

Code problem with time conditions


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Spatial @spatial Participant
Summary

This topic contains 7 replies,
has 6 voices, and was last updated by Vonasi
7 years, 9 months ago.

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