Stop for RSI Agita
Author: rickraphael
Creation Date: 5/1/2008 1:51 PM
profile picture

rickraphael

#1
Wealth-Lab Version 5 (.NET) 5.0

How does one go about adding a parameter stop to the RSI Agita script, with parameters 5% to 20%?
profile picture

Eugene

#2
CODE:
Please log in to see this code.
profile picture

rickraphael

#3
Thank you.
profile picture

Jojo142

#4
Eugene, I would like to create a stop loss from 1000 to 2000 points, based on the medium price of the many entries in the current position..could you help me...TKX ...I only have transformed the parts that I think that must be changed...


CODE:
Please log in to see this code.




CODE:
Please log in to see this code.


IS that correct?
profile picture

Jojo142

#5
CODE:
Please log in to see this code.


Please consider this programation at the end...
profile picture

Eugene

#6
Please consider using the CODE tags, it's very easy - just put the code snippet between the tags. It helps legibility. Thanks.

QUOTE:
I would like to create a stop loss from 1000 to 2000 points, based on the medium price of the many entries in the current position.


Here's my attempt (not tested):

CODE:
Please log in to see this code.
profile picture

Jojo142

#7
Hi Eugene,
This strategy seems to work but there is a little error...the stop loss is done in the right candle but the exit price is ok only for the last entrance, for the anterior it s different...could you have a look...tkx
profile picture

Eugene

#8
Please comment out the AtMarket exit, thus enabling the AvgEntryPrice stop only, and point to the erroneous trade using the data you've sent to us before.
profile picture

Jojo142

#9
Eugene,
I don t know if I have understood :you asked me to eliminate the exit atmarket? ... The trades are becoming confused because all trades are losing.
So I let the program as you passed me, please only modify the entrance as BuyatClose(bar)
trades :
At 01/july/08 10:45 buy at 64250
At 01/july/08 14:30 buy at 63700 then average=63975
At 02/july/08 17:00 buy at 62200 then average=63383
At 02/july/08 17:45 buy at 61620 then average=62942

trade stopped loss at 3/july/2008 11:45 in 60942 for the last entrance and 61310 for the others that is the open price.
profile picture

Eugene

#10
QUOTE:
I don t know if I have understood :you asked me to eliminate the exit atmarket? ...

Yes, including the condition. It makes sense for me to troubleshoot a part of program on its own.

When posting trades, please indicate your selected commission/slippage option and system parameters - so that I could match your figures. Currently they don't.
profile picture

Jojo142

#11
Ok Eugene, it s done...
Comissions : not applied for to this test
back test : nothing habilited
slippage : nothing habilited

trade :
At 04/january/08 12:30 buy at 62270
At 04/january/08 12:45 buy at 61580 then average=61925 stopped at 16/01/2008 14:30 at 59150 (open price) not OK
At 04/january/08 13:45 buy at 61180 then average=61676 stopped at 16/01/2008 14:30 at 59150 (open price) not OK
At 04/january/08 14:15 buy at 61050 then average=61520 stopped at 16/01/2008 14:30 at 59150 (open price) not OK
At 15/january/08 14:00 buy at 61050 then average=61326 stopped at 16/01/2008 14:30 at 59150 (open price) not OK
At 15/january/08 15:30 buy at 61050 then average=61150 stopped at 16/01/2008 14:30 at 59150 (open price) not OK
At 16/january/08 11:00 buy at 61050 then average=60837 stopped at 16/01/2008 14:30 at 58837 (??????????) not OK
At 16/january/08 11:00 buy at 61050 then average=60602 stopped at 16/01/2008 14:30 at 58602 OK!!

profile picture

Eugene

#12
I can not duplicate these entry times even with BuyAtClose. Indicate your parameters (if != default) or post the script as you have it.
profile picture

Jojo142

#13
CODE:
Please log in to see this code.

profile picture

Eugene

#14
Still no luck. Using 2 variations of your mini indice.txt.
profile picture

Jojo142

#15
??? I ve only upgrade the last days...I send it to you again...
profile picture

Eugene

#16
Have you pressed the "Compile" button? What are your data loading settings? Does the symbol exist in Symbol Info Manager and if yes, with which settings.

Don't forget to indicate your script parameters, if you've moved the parameter sliders.
profile picture

Eugene

#17
Joao

Please keep conversation in one place by answering questions here, and not in a support ticket.
profile picture

Jojo142

#18
Hi Eugene...I ve understand what happened, I forgot to actualise the last entry price I passed to you because i ve made a copy/paste and forgot to actualise the last entry prices at 61050...sorry...
So to be better , I m using the first data base again to work with the same datas exactly as you have. The entries continue the same...

trade :
At 04/january/08 12:30 buy at 62270
At 04/january/08 12:45 buy at 61580 then average=61925 stopped at 16/01/2008 14:30 at 59150 (open price) not OK
At 04/january/08 13:45 buy at 61180 then average=61676 stopped at 16/01/2008 14:30 at 59150 (open price) not OK
At 04/january/08 14:15 buy at 61050 then average=61520 stopped at 16/01/2008 14:30 at 59150 (open price) not OK
At 15/january/08 14:00 buy at 60550 then average=61326 stopped at 16/01/2008 14:30 at 59150 (open price) not OK
At 15/january/08 15:30 buy at 60270 then average=61150 stopped at 16/01/2008 14:30 at 59150 (open price) not OK
At 16/january/08 11:00 buy at 58960 then average=60837 stopped at 16/01/2008 14:30 at 58837 (??????????) not OK
At 16/january/08 11:00 buy at 58960 then average=60602 stopped at 16/01/2008 14:30 at 58602 OK!!

Have you pressed the "Compile" button? : compiled successfully
What are your data loading settings? Does the symbol exist in Symbol Info Manager and if yes, with which settings : I haven t understand...the datas are the first data I sent to you now

Don't forget to indicate your script parameters, if you've moved the parameter sliders : the program is exactly the last I informed at 9:50

no commission, slippage etc...
TKS
profile picture

Eugene

#19
I've just noticed that you made the code peek into the future by removing bar+1 from SellAtStop and changing it to bar. Before doing any further tests, revert the change by copying the code from my post @ 2/2/2009 3:06 PM. Using default parameters, the first trade should happen on 04/01/2008 13:15.

QUOTE:
At 04/january/08 12:30 buy at 62270


It's impossible to buy at this date. Using the default parameters (as you say in the ticket), the crossunder will happen no earlier than 12:45. I reviewed all of your 3 files and all they contain this line:

QUOTE:
4/01/2008 12:30 62270 62255 63350 63350


As you see, it is also impossible to BuyAtClose because the closing price is totally different. This could happen if you altered the code somehow, modified a strategy parameter etc.

Unfortunately, this passage is repeated over and over again in your support tickets and on the forum, but you should review everything very carefully before posting or contacting support.
profile picture

Jojo142

#20
OK Eugene, I make a mistake in this line really...but if you look now at 10 march 2008 or 3 july 2008, the exit of the position are made at different prices...
The reason why I change the condition buyAtmarket (bar +1) to enter in the position is that sometimes, the condition is given at the end of the day and the day after we have a gap..so the strategy buy after the gap...have you another idea to avoid this situation?

profile picture

Eugene

#21
QUOTE:
but if you look now at 10 march 2008 or 3 july 2008, the exit of the position are made at different prices...

The strategy does not trade on March, 10.

QUOTE:
or 3 july 2008

Are you sure?
QUOTE:
Position Symbol Quantity Entry Date Entry Price Exit Date Exit Price Profit % Profit $ Bars Held Profit per Bar Entry Name Exit Name MAE % MFE %
Long mini indice 1 02.07.2008 17:30 61 765.00 03.07.2008 18:45 59 500.00 -3.67 -2 265.00$. 42 -53.93$. Stopped at 2 000.00 -3.67 -0.11
Long mini indice 1 02.07.2008 18:15 61 690.00 03.07.2008 18:45 59 500.00 -3.55 -2 190.00$. 39 -56.15$. Stopped at 2 000.00 -3.55 0

Using the default stop loss value of 2000 as indicated by the exit name.
QUOTE:
so the strategy buy after the gap...have you another idea to avoid this situation?

Yes: ignore entry if gap was detected.
profile picture

Jojo142

#22
Eugene..please paste the strategy again..I don t understand where the mistake is...
I ve copied, your strategy from 2/2/2009 3:06 PM as you said. I m using the same data base I sent at first.
no comission, slippsage, etc...
my first trade is at 04 january 12:45 buy at 62255 (buy at market in the next candle after the signal...)

ntity-Entry-Date-Entry-Price-Exit-Date-Exit-Price-Profit-%-Profit-$-Bars-Held-Profit-per-Bar-Entry-Name-Exit-Name-MAE-%-MFE-%
Long-mini indice-1-02/07/2008-17:15-62200,00-03/07/2008-18:30-59825,00--3,82--2 375,00-€-42--56,55-€--Stopped-at-2000,00--3,86-0,31
Long-mini indice-1-02/07/2008-18:00-61620,00-03/07/2008-18:30-59825,00--2,91--1 795,00-€-39--46,03-€--Stopped-at-2000,00--2,95-1,01
Long-mini indice-1-03/07/2008-12:15-60965,00-03/07/2008-18:30-59595,00--2,25--1 370,00-€-26--52,69-€--Stopped-at-2000,00--2,25-1,65
profile picture

Jojo142

#23
Eugene...could you post your last script? TKS
profile picture

Jojo142

#24
I would like to modify the RSI agita strategy, because I would like to buy only (and only 1 time) if the candle is bullish and if the "normal condition" of buying had already been given before, in the last script, that is, price under last entry, rsi<level. I make this script but there is conflict between the variables and certainly many errors...could you help me? Thanks.

CODE:
Please log in to see this code.
profile picture

Eugene

#25
So you want to turn the strategy logic so that it would take a single position only?
profile picture

Jojo142

#26
Hi Eugene,
let me give you an example of what I would like to simulate :
RSI oversold 30
If The RSI falls from 33 to 24 , so in this candle it should have buy 2 times, if under last entry price (because level 30 --> 25 and RSI 24< 25 and 30). So I would like to buy only ONE TIME at the first bullish candle.
If the RSI continue falling, in the last strategy, it could have given another order to buy, I m still with a buy to do when the candle becomes bullish, so I will buy only 1 time....I the next candle becomes bullish, so i buy 1 time and the cicle reinitiate....I can buy again if there is a signal and a bullish candle...
profile picture

Eugene

#27
If I get it right, regardless of the size of the RSI move you buy only once but at the time of the first entry. Consequently, if the RSI falls from 33 to 24 when there already is an open position, the strategy buys two more?
profile picture

Jojo142

#28
the strategy buys when we have a crossunder of the rsi with the limit of overbought and if it falls 5 points more, it nuys again...so for example if the rsi falls from 32 to 4 for example, the agita strategy will buy 6 times in the candle.....
in my case I want to change it and buy only 1 time for this signal, and when the candle will be bullish...after that if we have another signal ...I want to buy again, whern the candle becomes bullish again...
profile picture

Eugene

#29
If I got that right, basically you make check if a position is created and prevent from re-entering on the same bar:
CODE:
Please log in to see this code.
profile picture

Jojo142

#30
not exactly Eugene...

if (CrossUnder(bar, rsi20, level))
if (Bars.Close[bar] < lastEntryPrice)

If those 2 conditions, are ok, I will buy only 1 time and always that those those conditions will appear again but only when the candle becomes bullish (so my idea is to turn a variable true when the 2 conditions are ok and when the can is bullish, the buy of 1 contract is started...)if the 2 conditions appear again ...same process....
profile picture

Eugene

#31
One more try:
CODE:
Please log in to see this code.
profile picture

Jojo142

#32
Eugene, I run the strategy..it seems to buy after bearish candle too... and sometimes it must have bought and didn t...for example on 19/august/2008 at 11:45...the level open falling from 36 to 28,... first candle is bullish, so ok, buy at next candle...but the price continue falling ...and at 10:45 it s under 25 so we have a crossunder of the rsi again so it should have bought at 11:45 after bullish candle..is it right?
profile picture

Eugene

#33
QUOTE:
it seems to buy after bearish candle too

No, this is not true. I have manually verified this by going through every secondary entry which - as per your description - should be done after a bullish candle. You can change the "bullish candle" definition as you like.

QUOTE:
and sometimes it must have bought and didn t...for example on 19/august/2008 at 11:45

No. On 19/august/2008 at 11:45, the strategy should not buy.

1. 18.08.2008 16:15. This is the 1st entry.
2. 19.08.2008 10:00. Could be another entry because there was a CrossUnder, but the candle is bearish - no entry.
3. At 11:45 there was a CrossOver of the oversold level. It means nothing to the system.

Sadly, despite our conversations in a support ticket, I would recommend that you review the QuickRef entries for CrossOver and CrossUnder until you understand the difference.
profile picture

Jojo142

#34
Dear Eugene, I think I have understand what a crossover and crossunder is...but probably there is a problem of communication with my english...
so please listen :
on 18/08/2008 16:15 : I don t want to buy in this candle because the candle before was bearish...the candle at 16:30 which close at 54350, so I buy atmarket in the next candle...54370

At 11:45 there was a CrossOver of the oversold level. It means nothing to the system : ok, in this candle we have a crossover but I want to buy in this candle because at 10:45 we had the condition to buy except the candle who was bearish..so I want to buy as soon as I have a bullish candle even if RSI is crossovering the limit 30...
profile picture

Jojo142

#35
I forgot 1 term...please read :
on 18/08/2008 16:15 : I don t want to buy in this candle because the candle before was bearish...the candle at 16:30 which close at 54350 WAS BULLISH, so I buy atmarket in the next candle...54370
profile picture

Eugene

#36
Starting from this point, please describe all what you want to implement as a checklist. What is required is a clear algorithm, free from any ambiguity. Every condition should be specified exactly, without double meanings. Thank you.
profile picture

Jojo142

#37
- when the rsi falls under the limit 30(crossunder) and the price in THIS CANDLE is under the last entry so I will buy 1 contract (buyatmarket(bar + 1)), but only when the candle becomes bullish and even if the price is over last entry or RSI> 30...
- each time that the condition " the rsi falls under the limit 30(crossunder) and the price in THIS CANDLE is under the last entry " I will buy again except if I have already a buy to be done...in that case I will buy only 1 TIME when the candle becomes bullish...
- I will sell my position as describe in the initial agita strategy, when RSI crossover overbought parameter or when stopped...
profile picture

Eugene

#38
QUOTE:
when the rsi falls under the limit 30(crossunder)


"the rsi falls under the limit 30" != "crossunder"

"crossunder" == falls through the limit 30

Which one you have in mind?

QUOTE:
the price in THIS CANDLE is under the last entry so I will buy 1 contract (buyatmarket(bar + 1)), but only when the candle becomes bullish and even if the price is over last entry or RSI> 30..


- "the price in THIS CANDLE is under the last entry" & "and even if the price is over last entry or RSI> 30..."

These conditions clearly contradict each other.

Please don't rush to answer. Better double check everything and have a clear algorithm.
profile picture

Jojo142

#39
falls through the limit 30 ... it s this one... but if in this candle, RSI crossunder the limit and price at close is under last entry, we will buy as soon as the 1st candle becomes bullish , independently of the new value of rsi and price of the market...

The price must be under the last entry only in the candle that gives the signal...at the bullish candle where we buy, we don t care about this fact of being or not over or under the last entry...
profile picture

Eugene

#40
OK we're getting closer. But given that you don't care if the RSI could have risen over 30, it's not the RSI Agita any more. The inherent loop will simply not let you buy when the RSI is above its oversold value. Let me think about it.
profile picture

Jojo142

#41
you re right Eugene, it s not more the RSI Agita...
I want to try this variation because the problem I have regarding to this strategy is that it s buying when the prices are fallen...And in my mind and experience, I only want to buy when the prices are increasing, not falling...
I don t care if RSI is over 30 because my exit objective is RSI at 55-60, and I want to buy because the RSI agita had given the signal before...sometimes it will buy better, sometimes worst...
profile picture

Eugene

#42
QUOTE:
- each time that the condition " the rsi falls under the limit 30(crossunder) and the price in THIS CANDLE is under the last entry " I will buy again except if I have already a buy to be done...in that case I will buy only 1 TIME when the candle becomes bullish...


Well, I don't see how your second entry rule and the decrementing loop can live together. To get an entry, it must be possible to break the loop to buy if the RSI is above oversold.ValueInt. Without getting into the unneeded complexity, I can create a strategy but for that will have to get rid of that loop. So, no more Agita-like decrement of the RSI. OK?

profile picture

Jojo142

#43
Ok Eugene... but is it possible to buy again, if for example after the rsi crossover the oversold value, it falls again under it?

profile picture

Eugene

#44
QUOTE:
but is it possible to buy again, if for example after the rsi crossover the oversold value, it falls again under it?

Of course.

Here's my take:

CODE:
Please log in to see this code.
profile picture

Jojo142

#45
Eugene thanks for your help...but have a look in the chart it still seems to buy many times after a bearish candle...
profile picture

Jojo142

#46
Eugene I ve just detected that we can have different chart because I just discovered that in my provider os candle signals, the order of values are : date, close, low, high and open..so it can explain some diferencies we had in your and mine charts...
profile picture

Eugene

#47
QUOTE:
the order of values are : date, close, low, high and open..so it can explain some diferencies we had in your and mine charts...

34500 "errors" after checking it with "Bad History Data Check". Doh! :)

QUOTE:
but have a look in the chart it still seems to buy many times after a bearish candle...

I see, wait a bit...

Update:
Although the latest iteration has just been uploaded (see above), I don't feel like it is what you want. It doesn't seem logical any more, because as you know the RSI decrement was ditched. What's the difference between these 2 rules, after all?

From this moment, no update will follow until I see an algorithm with short, clear-cut conditions.
profile picture

Jojo142

#48
Hi Eugene...
If we change the check of entry saying that if RSI crossunder oversoldvalue (no more level parameter), we will buy 1 contract as soon as candle becomes bullish (in that case, we will buy only one time each time that the rsi falls under overbought value), the price have to exit to oversold levels and return to it to buy again)...
exit if stopped or when RSI crossover overbought value...
profile picture

Jojo142

#49
and no more test of beeing lower than last entry price
profile picture

Jojo142

#50
Eugene...I just check the chart again with your last script...the only error I see is in the first entry...it buys will bullish or bearish candle..so I only want to buy after bullish candle..the entries after this one are ok...
profile picture

Eugene

#51
QUOTE:
I just check the chart again with your last script...the only error I see is in the first entry...it buys will bullish or bearish candle..

Double check it. Have you noticed this condition?
CODE:
Please log in to see this code.

It will buy next bar at market if only the current candle was bullish.

Since you don't want to honor my repeated requests to provide a short, concise checklist with algorithmic conditions - which is a must before doing any programming - I consider any further efforts without such a checklist to be a waste of time.
profile picture

Jojo142

#52
Sorry Eugene I check again it s ok....
2 more question :
- on 2/jun/08 why don t we have a buy after the 1st bullish candle at 16:15, only at 16:45, the same on 15/july/2008, why don t we have a buy after the 1st bullish candle at 10:45
- it must be the same problem...on 2/feb/2009, no bought was done after the rsi crossunder the oversold value and after a bullish candle...

profile picture

Jojo142

#53
for the algoritm..i beg your pardon but I m not a specialist and I don t know how to make it clear...but it s pratically the end...the last thing is im my last post...as I said before, as soon as the rsi crossunder the oversold value limit, I want to buy 1 contract, when candle becomes bullish even if rsi has crossover the oversold value again...
profile picture

Jojo142

#54
Eugene,
I think that if we change line 87...okToBuy2 = false, moving it after if buyatmarket..it will be what I want...
but how must be the script??

else
if( okToBuy2 )
{
if( bullishCandle )
BuyAtMarket(bar + 1, "bullish candle") AND okToBuy2 = false;
;
}
profile picture

Jojo142

#55
line 77...
profile picture

Jojo142

#56
Eugene, I ve solved the problem... it s ok now....tks for your help..
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).