long / short Expand / Collapse
Author
Message
Posted 9/2/2010 7:54:04 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 9/8/2010 4:33:45 PM
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.
Post #1926
Posted 9/2/2010 8:15:53 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 9/8/2010 4:33:45 PM
Posts: 4, Visits: 41
just to be clear
Post #1927
Posted 9/3/2010 12:28:33 PM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 2/7/2012 10:15:57 AM
Posts: 445, Visits: 818
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;




Post #1935
Posted 9/3/2010 8:05:55 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 9/8/2010 4:33:45 PM
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

Post #1938
Posted 9/8/2010 2:40:51 PM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 2/7/2012 10:15:57 AM
Posts: 445, Visits: 818
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;

Edited: 9/13/2010 12:11:39 AM by black
Post #1959
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Admin

All times are GMT -5:00, Time now is 11:32am


© 2009 Actforex.com Terms of Use