Spread trading with ADE and ELCollections
Posted: Feb 14 2024
Hi,
I was trying to write a trading system which uses ADE and ELCollections for spread trading.
The idea I came up with was to use 5 charts, with the following roles:
Now, my question is: is there a simpler way to do this?
Thanks!
I was trying to write a trading system which uses ADE and ELCollections for spread trading.
The idea I came up with was to use 5 charts, with the following roles:
- charts 1 and 2 are the "background", i.e. they contain the signals which are used for trading, but simply send the current openpositionprofit;
- chart 3 is the "sender"; it receives the current profits from charts 1 and 2 and decides whether a given portfolio SL/TP has been reached;
- charts 4 and 5 also contain the signals used for trading, and receive from chart 3 an instruction to close the position if the SL/TP has been reached.
Code: Select all
inputs: nameSender(""), name1(""), name2(""), spread(0), sender(0), background(0), firstSignal(true), slPortf(1000), tpPortf(300);
variables: profitOne(0), profitTwo(0), class("sigOne&sigTwo%sender"), mapsigOne(MapSN.New), mapsigTwo(MapSN.New), mapSender(MapSN.New),
instruction(0);
if background = 1 then
begin
if firstSignal then
begin
if close crosses above (close data2) then
sellshort next bar market;
if close crosses below (close data2) then
buytocover next bar market;
profitOne = 0;
if marketposition = -1 then
profitOne = openpositionprofit;
MapSN.Put(mapsigOne, "sigOne", profitOne);
ADE.PutBarInfo("sigOne", symbolName, ADE.BarInterval, ADE.BarID, mapsigOne);
end
else
begin
if close crosses below (close data2) then
buy next bar market;
if close crosses above (close data2) then
sell next bar market;
profitTwo = 0;
if marketposition = 1 then
profitTwo = openpositionprofit;
MapSN.Put(mapsigTwo, "sigTwo", profitTwo);
ADE.PutBarInfo("sigTwo", symbolName, ADE.BarInterval, ADE.BarID, mapsigTwo);
end;
end;
if sender = 1 then
begin
ADE.GetBarInfo("sigOne", name1, 1440, ADE.BarID, mapsigOne);
value1 = MapSN.Get(mapsigOne, "sigOne");
ADE.GetBarInfo("sigTwo", name2, 1440, ADE.BarID, mapsigTwo);
value2 = MapSN.Get(mapsigTwo, "sigTwo");
instruction = 0;
if (value1 + value2 < -slPortf) or (value1 + value2 > tpPortf) then
instruction = 1;
MapSN.Put(mapSender, "sender", instruction );
ADE.PutBarInfo("sender", symbolName, ADE.BarInterval, ADE.BarID, mapSender);
end;
if spread = 1 then
begin
ADE.GetBarInfo("sender", nameSender, 1440, ADE.BarID, mapSender);
value1 = MapSN.Get(mapSender, "sender");
if value1 = 1 then
begin
sell next bar market;
buytocover next bar market;
end;
if firstSignal then
begin
if close crosses above (close data2) then
sellshort next bar market;
if close crosses below (close data2) then
buytocover next bar market;
end
else
begin
if close crosses below (close data2) then
buy next bar market;
if close crosses above (close data2) then
sell next bar market;
end;
end;
Thanks!