|
datasos
|
Posted Thursday, September 02, 2010
|
|
Group: Forum Members
Last Active: Wednesday, September 08, 2010
Posts: 4,
Visits: 41
|
Hi,
is it possible (I believe it is) to use a strategy that will, (under conditions) close long positions and open a Short and vice versa at the same level/price. In other words we are always in positions (buy or sell) depending of signals we provide. And one more thing, can we control multiple orders in a way, that always just one positions is active or if we have a positions don't open new one.
I just find this forum and before I start with learning some code It will be very useful to know can we automate buy / sell strategies as I described.
|
|
datasos
|
Posted Thursday, September 02, 2010
|
|
Group: Forum Members
Last Active: Wednesday, September 08, 2010
Posts: 4,
Visits: 41
|
just to be clear
|
|
black
|
Posted Friday, September 03, 2010
|
|
Group: Forum Members
Last Active: 3 hours ago
Posts: 462,
Visits: 848
|
How's this:
if (SOME BUY CONDITION IS MET) then
begin
if (TradeList.Count > 0) then
begin
for i:=TradeList.Count-1 downto 0 do
begin
if (TradeList.Get(i).BuySell = bsSell) then
begin
CloseTrade(TradeList.Get(i), TradeList.Get(i).Amount, TraderRange, TradeList.Get(i).Tag);
end;
end;
end;
CreateOrder(History.Instrument, Account, Amount, bsBuy,
History.Instrument.buy - Point*Stop,
History.Instrument.buy + Point*Limit, TraderRange, 'TradeBuy');
end;
if (SOME SELL CONDITION IS MET) then
begin
if (TradeList.Count > 0) then
begin
for i:=TradeList.Count-1 downto 0 do
begin
if (TradeList.Get(i).BuySell = bsBuy) then
begin
CloseTrade(TradeList.Get(i), TradeList.Get(i).Amount, TraderRange, TradeList.Get(i).Tag);
end;
end;
end;
CreateOrder(History.Instrument, Account, Amount, bsSell,
History.Instrument.Sell + Point*Stop,
History.Instrument.Sell - Point*Limit, TraderRange, 'TradeSell');
end;
Sometimes it is advantageous to split things up, doing all the Closes before any of the new Opens, like the below.
if (SOME BUY CONDITION IS MET)
and (TradeList.Count > 0) then
begin
for i:=TradeList.Count-1 downto 0 do
begin
if (TradeList.Get(i).BuySell = bsSell) then
begin
CloseTrade(TradeList.Get(i), TradeList.Get(i).Amount, TraderRange, TradeList.Get(i).Tag);
end;
end;
end;
if (SOME SELL CONDITION IS MET)
and (TradeList.Count > 0) then
begin
for i:=TradeList.Count-1 downto 0 do
begin
if (TradeList.Get(i).BuySell = bsBuy) then
begin
CloseTrade(TradeList.Get(i), TradeList.Get(i).Amount, TraderRange, TradeList.Get(i).Tag);
end;
end;
end;
if (SOME BUY CONDITION IS MET) then
begin
CreateOrder(History.Instrument, Account, Amount, bsBuy,
History.Instrument.buy - Point*Stop,
History.Instrument.buy + Point*Limit, TraderRange, 'TradeBuy');
end;
if (SOME SELL CONDITION IS MET) then
begin
CreateOrder(History.Instrument, Account, Amount, bsSell,
History.Instrument.Sell + Point*Stop,
History.Instrument.Sell - Point*Limit, TraderRange, 'TradeSell');
end;
|
|
datasos
|
Posted Friday, September 03, 2010
|
|
Group: Forum Members
Last Active: Wednesday, September 08, 2010
Posts: 4,
Visits: 41
|
thanks black already learning lot from your examples ...
If I can ask few more things
- default RSI osc are calculated on EMA ? ... what if I need a RSI on WildersAverage ... ?
- what if I need a value of RSI based on Open price and RSI based on Close price, separately
- How to displace EMA horizontal ...
generally I'm interested in whether it is better/faster declare all in the indicators (EMA displaced, RSI Open, RSI Close, etc.). and then call the value of this new indicators in the Strategy and further combine them OR is it allowed/faster to work directly in the strategy?
example: as RSI default is (14, Close) I can use this but for a RSI (14, Open) I need to made a new indicator lets say RSI_Open and call them in Strategy, OR declare all (Open/Close variations) in strategy ?
for me it's more practical to work in Strategy directly but I'm new here so maybe this is not the right way and I not need lines on the chart - only the final product of calculations in the form of arrows ... I guess we can draw arrows or defined it in the Strategy itself ?
PS. probably my questions are beginners but I'm at # beginning
|
|
black
|
Posted Wednesday, September 08, 2010
|
|
Group: Forum Members
Last Active: 3 hours ago
Posts: 462,
Visits: 848
|
Most of us are Beginners. My scripting is simple. Scriptor - and a few others - is the one who knows how to write scripts for Strategies.
You need to calculate your own RSI.
The formula I have for the RSI is shown below. It is NOT complete for ActTrader as shown below. You need to finish it for ActTrader. Is it the correct formula? Is there a better form of it somewhere?
If you want to base your RSI calculations on something other than the "close" simply replace the "close" in the formula with something else... like an exponential MA - MA.Graph.Last(?), or a simple MA - MA.Graph.Last(?), or a Stochastic - Stochastic.GraphK.Last(?), or a MACD - MACD.Graph.Last(?), or an Aroon - Aroon.Graph.Last(?), or anything else. Of course, you need to add the indicator you use to your Strategy same as usual.
I haven't tried it, but it might be interesting.
-------------------------------------------------------------------
if close(1) > close(2) then
up := close(1) - close(2);
dn : =0;
if close(1) <= close(2) then
up := 0;
dn := close(2) - close(1);
upavg := ((upavg(1)*(Period-1))+up)/Period;
dnavg := ((dnavg(1)*(Period-1))+dn)/Period;
RSI := upavg/(upavg+dnavg)*100;
-------------------------------------------------------------------
-------------------------------------------------------------------
A method for calculating your own SMA or EMA.
var // declarationofthevariables
Sma : Double; // Simple Moving Average
Ema : Double; // Exponential Moving Average
SmaL : Double; // Previous Simple Moving Average
EmaL : Double; // Previous Exponential Moving Average
SmaPer, EmaPer, i, k : Integer;
procedureOnCreate;
begin
AddIntegerSetting(@SmaPer,'SMAPeriod',12); // SMA Period
AddIntegerSetting(@EmaPer,'EMAPeriod',16); // EMA Period
procedureOnStart;
begin
Point:=History.Instrument.PointSize;
EmaL:=(2/(EmaPer+1)*(History.Last(2).Close-History.Last(3).Close))+History.Last(3).Close;
Ema:=(2/(EmaPer+1)*(History.Last(1).Close-EmaL))+EmaL;
Sma:=0;
SmaL:=0;
SmaPer:=SmaPer+1;
for i:=SmaPer-1 downto 1 do
begin
k:=i+1;
Sma:=Sma+History.Last(i).Close;
SmaL:=Sma+History.Last(k).Close;
end;
SmaPer:=SmaPer-1;
Sma:=Sma/SmaPer;
SmaL:=SmaL/SmaPer;
procedureOnNewCandle;
begin
Ema:=(2/(EmaPer+1)*(History.Last(1).Close-EmaL))+EmaL;
Sma:=0;
SmaPer:=SmaPer+1;
for i:=SmaPer-1 downto 1 do
begin
Sma:=Sma+History.Last(i).Close;
end;
SmaPer:=SmaPer-1;
Sma:=Sma/SmaPer;
// ADD YOUR CALCULATIONS FOR MAKING YOUR STRATEGY WORK HERE.
SmaL:=Sma;
EmaL:=Ema;
Sunday, September 12, 2010 by
black
|