Mike,
Trying to get the sell orders to open upon RSI rise above 75/'then' fall below 70. Likewise trying to get RSI buy orders to open upon RSI fall below 25/'then' rise above 30. Obviously it currently opens/immediately closes orders constantly with code as shown. I am a code rookie and cannot quite figure out how to code the two RSI levels into the 'IF' lines. Can this be done and any hints on how to alter this?:
// if there is no order and RSI goes > 75 then < 70
// then open SELL order
if (OrderHandle = -1) and (RSI < 70) then
begin
SendInstantOrder(Symbol, op_Sell, LotSize, 0, 0, '', 0, OrderHandle);
OrderStyle := tp_Sell;
OpenTime := Time(0);
// if there is no order and RSI goes < 25 then > 30
// then open BUY order
if (OrderHandle = -1) and (RSI > 30) then
begin
SendInstantOrder(Symbol, op_Buy, LotSize, 0, 0, '', 0, OrderHandle);
OrderStyle := tp_Buy;
OpenTime := Time(0);
end;
end;
RSI Strategy Code Query
- Terranin
- Site Admin
- Posts: 833
- Joined: Sat Oct 21, 2006 4:39 pm
Re: RSI Strategy Code Query
Beaker wrote:Mike,
Trying to get the sell orders to open upon RSI rise above 75/'then' fall below 70. Likewise trying to get RSI buy orders to open upon RSI fall below 25/'then' rise above 30. Obviously it currently opens/immediately closes orders constantly with code as shown. I am a code rookie and cannot quite figure out how to code the two RSI levels into the 'IF' lines. Can this be done and any hints on how to alter this?:
// if there is no order and RSI goes > 75 then < 70
// then open SELL order
if (OrderHandle = -1) and (RSI < 70) then
begin
SendInstantOrder(Symbol, op_Sell, LotSize, 0, 0, '', 0, OrderHandle);
OrderStyle := tp_Sell;
OpenTime := Time(0);
// if there is no order and RSI goes < 25 then > 30
// then open BUY order
if (OrderHandle = -1) and (RSI > 30) then
begin
SendInstantOrder(Symbol, op_Buy, LotSize, 0, 0, '', 0, OrderHandle);
OrderStyle := tp_Buy;
OpenTime := Time(0);
end;
end;
Ok, you need to detect crossing RSI up to 75 first, so you need to track this condition:
Code: Select all
var
rsi75: boolean; // this variable will track crossing rsi 75
procedure Reset; stdcall;
begin
...
rsi75 := false; // first initialization (no crossing yet)
end;
procedure GetSingleTick; stdcall;
begin
...
if OrderHandle = -1 then // tracking only when no orders opened
begin
if RSI > 75 then
rsi75 := true; // detected crossing and saved it for future
if RSI < 50 then
rsi75 := false; // reset it when RSI falling below 50
if rsi75 and (RSI < 70) then
... // here we go - we had RSI detected over 75 before and now it is below 70 so we can open an order
end;
end;
Hasta la vista
Mike
Mike
Who is online
Users browsing this forum: No registered users and 20 guests