Find correct highest and lowest value

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #103594 quote
    Parimal Patel
    Participant
    New

    Hi

    I have just started using Pro Real Code software. I am trying to find Highest value between my last order (sell) and  current position, but endup with wrong result.

    e.g.  I have executed my first previous order on 1000. Before placing 2nd order I would like to know that price had been gone above to 1100 or not. Currently I am using following code.

    mylastTradeIndex = tradeindex(1)
    higestSinceLastTrade = highest[BarIndex - (mylastTradeIndex)](high)

    Above code return 1175, as graph show that value only increse to 1030.

    As i am new on this platform any help will be appriciated.

    #103596 quote
    Vonasi
    Moderator
    Master

    Welcome to the forums. I will move your topic to the ProOrder forum as that is the correct place for it as it is an automated strategy question and not a platform issue. Please try to post in the correct forum with future topics.

    Try the following to record the highest high since the last trade closed:

    if strategyprofit <> strategyprofit[1] then 
    hh = high
    endif
    
    if not onmarket then
    hh = max(hh,high)
    endif
    
    
    #103606 quote
    Parimal Patel
    Participant
    New

    I have tried above code but it doesn’t return correct result.

    e.g. if First order (sell) executed on 1100 than I want to executed 2nd order only if market went to more than 50 points up (means reach above 1150) and come down to below 1100.

    #103612 quote
    Vonasi
    Moderator
    Master

    Sorry – I didn’t realise that you wanted someone to write the whole thing rather than just fix the bit of code that you posted!

    You could try something like this:

    defparam cumulateorders = false
    
    //Save TradePrice if on market
    if onmarket then
    lastprice = tradeprice
    endif
    
    //Reset hh when trade closed
    if strategyprofit <> strategyprofit[1] then
    hh = high
    endif
     
    //Record Highest High since last trade closed
    if not onmarket then
    hh = max(hh,high)
    endif
    
    //Get first trade opened
    if (your entry conditions) and strategyprofit = 0 then
    buy 1 contract at market
    endif
    
    //Only open following trades if they meet the new conditions
    if (your entry conditions) and close < lastprice and hh - lastprice > 50 and strategyprofit <> 0 then
    buy 1 contract at market
    endif
    
    graph hh
    #103613 quote
    robertogozzi
    Moderator
    Master

    >> Please update your country flag in your profile. Thank you 🙂 <<

    Vonasi thanked this post
    #103639 quote
    Parimal Patel
    Participant
    New
    Thanks for help I had no intension that someone write code for me. I already written my code but I am getting wrong result into lowest and highest all the time. I will try above logic and let you know about result.
    #103640 quote
    Parimal Patel
    Participant
    New
    I have tried above code but still not getting accurate result. Find my below code which is executing every second.
    DEFPARAM PRELOADBARS = 3000
    ONCE count = 0
     
    once defaultQty = 1
    once defaultVariationForFirstDrop = 75
    once defaultVariation = 50
    once hh = high
    
    // Previous or last Trade information
    mylastTradePrice = tradeprice(1)
    mylastTradeIndex = tradeindex(1)
     
    // Number of Short position we have created so far
    countOfShortPosition = COUNTOFSHORTSHARES
     
     
    if countOfShortPosition = 0 and not LONGONMARKET and mylastTradeIndex = 0 AND count = 0 then
    BUY 1 contract AT MARKET
    count = count + 1
    elsif LONGONMARKET and count = 1 then
    sell at market
    count = count + 1
    elsif count >= 2 and count <= 9 then
    // here I want to execute following command only when market went to 50 points high and come down to lower than last purchase price.
    // e.g. if previous order (when count = 1) executed at 500 point than following order (10 qty) only execute when price touch to 550 and comedown back to 500 or lower
    // I have tried higest[barindex - tradeindex(1)] to find highest point but never get correct result. 
    
    SELLSHORT 10 contract at market
    endif
    First Buy and Sell is giving me reference point for future trade. 3rd block should execute only when market went to more than 50 points up (in compare to lastprice) and come down back to lower than lastprice. I have spent so much time but cannot figure out why every sell order execute on every single second. it is simple program but giving so much pain, might be because I am new on this platform.
    #103644 quote
    Vonasi
    Moderator
    Master
    Your code is very confused and so it is difficult to work out what you are trying to actually do. You have a BUY and and a SELL and a couple of SELLSHORT’s but no EXITSHORT. In your code absolutely everything is enclosed in the following condition so if this is not true then nothing happens:
    if countOfShortPosition = 0 and not LONGONMARKET and mylastTradeIndex = 0 AND count = 0 then
    I would suggest that you explain clearly what you are trying to do with all entry and exit conditions clearly explained and then it might be easier for someone to code something for you. The code I provided does what you requested in post #103606 so either you explained it wrong or you want something completely different! 🙂
    #103650 quote
    Parimal Patel
    Participant
    New
    I have simplified my code and added more description.
    #103657 quote
    Vonasi
    Moderator
    Master
    So it seems that for some reason you want to just buy the first bar after the strategy is started and sell it immediately just to get the start price? Why not just store the first bars close as the start price rather than actually trade and definitely lose the spread in one second? Then you want to see if price rises 50 points higher than that price and then drops below it. At this point you want to short with a position size of 10. This new purchase price becomes your new price to use for comparison once this trade is finished. You have no exit conditions or take profit/stop loss levels so I assume there is more code that we cannot see? If my interpretation is correct then this should do it although it is impossible to test due to the lack of exit conditions:
    defparam cumulateorders = false
     
    //Save TradePrice if on market
    if onmarket then
    lastprice = tradeprice
    endif
     
    //Reset hh when trade closed
    if strategyprofit <> strategyprofit[1] then
    hh = high
    endif
     
    //Record Highest High since last trade closed
    if not onmarket then
    hh = max(hh,high)
    endif
     
    //Get starting price of first bar
    if flag = 0 then
    lastprice = close
    flag = 1
    endif
     
    //Open trades if they meet the conditions
    if flag = 1 and close < lastprice and hh - lastprice > 50 then
    sellshort 10 contract at market
    endif
    
    graph hh
    #103663 quote
    Vonasi
    Moderator
    Master
    Obviously get rid of line 1 if you actually want to accumulate positions. I also forgot that your code version will only place a maximum of eight trades before it stops trading forever. To get the same thing try this:
    //Save TradePrice if on market
    if onmarket then
    lastprice = tradeprice
    endif
     
    //Reset hh when trade closed
    if strategyprofit <> strategyprofit[1] then
    hh = high
    endif
     
    //Record Highest High since last trade closed
    if not onmarket then
    hh = max(hh,high)
    endif
     
    //Get starting price of first bar
    if flag = 0 then
    lastprice = close
    flag = 1
    endif
     
    //Open trades if they meet the conditions
    if flag = 1 and close < lastprice and hh - lastprice > 50 and count < 8 then
    sellshort 10 contract at market
    count = count + 1
    endif
    
    Nicolas thanked this post
Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.

Find correct highest and lowest value


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

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

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