Start to look for conditions after crossover
Forums › ProRealTime English forum › ProOrder support › Start to look for conditions after crossover
- This topic has 5 replies, 3 voices, and was last updated 1 year ago by Johann.
-
-
01/30/2023 at 11:59 AM #208741
Trying to get the algorithm to wait for a crossover between the two moving averages to occur, and then checks the RSI value in the next 5 candles. If the RSI is below 30 in one of those candles, the algorithm generates a buy signal. This way, the algorithm waits for confirmation of the oversold condition before entering a trade. This code do not work it trades on the crossover but the crossover should only indicate the starting point from where it should look at the RSI
Start condition check1234567891011121314151617181920212223242526272829303132// Define the lengths of the moving averages and RSI indicatormaLength1 = 20maLength2 = 30rsiLength = 14// Calculate the moving averages and RSI valuema1 = Average[maLength1](close)ma2 = Average[maLength2](close)nrsi = rsi[rsiLength](close)// Identify the cross over using the moving averagescrossover = 0if ma1 > ma2 and ma1[1] < ma2[1] Thencrossover = 1 // moving average crossover occurredEndif// Use the cross over signal and RSI value to determine the entry pricedirection = 0if crossover = 1 Thenfor i = 0 to 4if nrsi[i] < 30 Thendirection = 1 // buyEndifNEXTEndifIf direction = 1 ThenBuy 1 contract at marketEndif// Stops and targetsSET STOP pLOSS 100SET TARGET pPROFIT 10001/31/2023 at 8:23 AM #20880002/01/2023 at 6:13 AM #20888802/01/2023 at 6:49 AM #208889Hi JS, nope unfortunately it does not work. The idea is that the algo should look at the next 5 bars whether the RSI is in oversold territory just after the cross over up of the 20SMA and 30SMA. The trade has to take place within 5 bars after the cross over. If the RSI does not go into oversold territory within the next 5 bars the trade aborts and wait for the next cross over.
02/01/2023 at 10:05 AM #208902Here is a new attempt, store the barindex of the event, then check bars elasped since. Not tested.
12345678910111213141516171819202122232425262728// Define the lengths of the moving averages and RSI indicatormaLength1 = 20maLength2 = 30rsiLength = 14// Calculate the moving averages and RSI valuema1 = Average[maLength1](close)ma2 = Average[maLength2](close)nrsi = rsi[rsiLength](close)// Identify the cross over using the moving averagesif ma1 > ma2 and ma1[1] < ma2[1] Thencrossover = barindex // moving average crossover occurred = store the barindexEndif// Use the cross over signal and RSI value to determine the entry priceif barindex-crossover <= 5 and crossover>0 Then //crossover occured less than 5 bars agoif nrsi < 30 ThenBuy 1 contract at marketcrossover = 0 //reset and prevent next order with same crossoverEndifendif// Stops and targetsSET STOP pLOSS 100SET TARGET pPROFIT 1001 user thanked author for this post.
02/01/2023 at 1:46 PM #208911 -
AuthorPosts
Find exclusive trading pro-tools on