Find correct highest and lowest value
Forums › ProRealTime English forum › ProOrder support › Find correct highest and lowest value
- This topic has 10 replies, 3 voices, and was last updated 6 years ago by
Vonasi.
-
-
07/27/2019 at 9:25 AM #103594
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.
highest return wrong result12mylastTradeIndex = 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.
07/27/2019 at 10:27 AM #103596Welcome 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:
1234567if strategyprofit <> strategyprofit[1] thenhh = highendifif not onmarket thenhh = max(hh,high)endif07/27/2019 at 1:17 PM #103606I 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.
07/27/2019 at 2:15 PM #103612Sorry – 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:
12345678910111213141516171819202122232425262728defparam cumulateorders = false//Save TradePrice if on marketif onmarket thenlastprice = tradepriceendif//Reset hh when trade closedif strategyprofit <> strategyprofit[1] thenhh = highendif//Record Highest High since last trade closedif not onmarket thenhh = max(hh,high)endif//Get first trade openedif (your entry conditions) and strategyprofit = 0 thenbuy 1 contract at marketendif//Only open following trades if they meet the new conditionsif (your entry conditions) and close < lastprice and hh - lastprice > 50 and strategyprofit <> 0 thenbuy 1 contract at marketendifgraph hh07/27/2019 at 2:24 PM #103613>> Please update your country flag in your profile. Thank you 🙂 <<
1 user thanked author for this post.
07/28/2019 at 3:03 AM #103639Thanks 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.
07/28/2019 at 5:19 AM #103640I have tried above code but still not getting accurate result. Find my below code which is executing every second.
1234567891011121314151617181920212223242526272829DEFPARAM PRELOADBARS = 3000ONCE count = 0once defaultQty = 1once defaultVariationForFirstDrop = 75once defaultVariation = 50once hh = high// Previous or last Trade informationmylastTradePrice = tradeprice(1)mylastTradeIndex = tradeindex(1)// Number of Short position we have created so farcountOfShortPosition = COUNTOFSHORTSHARESif countOfShortPosition = 0 and not LONGONMARKET and mylastTradeIndex = 0 AND count = 0 thenBUY 1 contract AT MARKETcount = count + 1elsif LONGONMARKET and count = 1 thensell at marketcount = count + 1elsif 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 marketendifFirst 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.
07/28/2019 at 9:43 AM #103644Your 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:
1if countOfShortPosition = 0 and not LONGONMARKET and mylastTradeIndex = 0 AND count = 0 thenI 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! 🙂
07/28/2019 at 11:55 AM #103650I have simplified my code and added more description.
07/28/2019 at 4:20 PM #103657So 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:
1234567891011121314151617181920212223242526272829defparam cumulateorders = false//Save TradePrice if on marketif onmarket thenlastprice = tradepriceendif//Reset hh when trade closedif strategyprofit <> strategyprofit[1] thenhh = highendif//Record Highest High since last trade closedif not onmarket thenhh = max(hh,high)endif//Get starting price of first barif flag = 0 thenlastprice = closeflag = 1endif//Open trades if they meet the conditionsif flag = 1 and close < lastprice and hh - lastprice > 50 thensellshort 10 contract at marketendifgraph hh07/28/2019 at 4:48 PM #103663Obviously 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:
1234567891011121314151617181920212223242526//Save TradePrice if on marketif onmarket thenlastprice = tradepriceendif//Reset hh when trade closedif strategyprofit <> strategyprofit[1] thenhh = highendif//Record Highest High since last trade closedif not onmarket thenhh = max(hh,high)endif//Get starting price of first barif flag = 0 thenlastprice = closeflag = 1endif//Open trades if they meet the conditionsif flag = 1 and close < lastprice and hh - lastprice > 50 and count < 8 thensellshort 10 contract at marketcount = count + 1endif1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on