Lotsize depenting on Balance Expand / Collapse
Author
Message
Posted 7/16/2010 7:12:29 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 7/21/2010 11:47:44 AM
Posts: 5, Visits: 29
Hey @all.

I´m a very new one here inside and i´ve tried to find a solution for this. But i couldn´t.

I´m looking for a code that allways calculate the Lotsize depending on the actual account balance.

Something like: Amount(Lot) = Balance / 1000

If the account balance is 1.000 $ then the amount(Lot) should be 1
..................................2.000 $ ...........................................2
..................................3.000 $ ...........................................3

...

If anyone has an idea how to code this would be greadfull.

Edited: 7/16/2010 7:14:22 AM by upps
Post #1780
Posted 7/19/2010 8:02:28 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 7/21/2010 11:47:44 AM
Posts: 5, Visits: 29
If tried it this way. But it goes from 1 Lot direct to 100 and then 50, 28, 19 ...

I dont know what the mistake is. Any suggestions welcomed ...

// this procedure runs when some changes occur in the Open Positions list
procedure OnTradeChange(const Action: TDataModificationType; const Trade: TTrade; );
begin

Amount:=int(trunc(Trade.Account.Equity/10000));

EquityLast:=Trade.Account.Equity;

end;
Post #1787
Posted 7/20/2010 5:46:08 AM


Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 1/27/2012 12:53:25 PM
Posts: 201, Visits: 295
Hi, upps!
Amount – is the variable that you’ve already used in AddFloatSetting(@Amount, 'Amount(Lots)', 1);
So you should change the variable name, for example into MyAmount.


Best regards!
Post #1789
Posted 7/20/2010 9:03:42 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 7/21/2010 11:47:44 AM
Posts: 5, Visits: 29
Thanks for reply.

There seems to be now way to get the balance or equity in real. In testmode there is allways an balance of 100000 and an equity of 121000.

I can´t get it working to calculate the Lots depending on the acutaly runing balance:-(
Post #1790
Posted 8/29/2010 11:20:20 AM
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
I wonder if this will work.

====================================

const
  StrategyName = 'Amount Regulator';

var    //declaration of the variables
  History: TCandleHistory;
  Account: TAccount;
  Regulator, Stop, Limit, Amount, AmountOrig, Point: Double;
  TraderRange: Integer;
  MACD: TIndicatorMACD;

/////////////////////////////////////////////////////////////////////////// 

procedure OnCreate;
begin
  AddCandleHistorySetting(@History, 'History', '', CI_30_Minutes, 100);   //setting up the chart history
  History.OnNewCandleEvent := @OnNewCandle;   //indicating the procedure to run when a new candle opens
  AddFloatSetting(@Regulator, 'Lot Control:', 500);     //Divide the Balance by this amount to get the lots.
  AddFloatSetting(@Limit, 'Limit', 30);   //setting up limit in pips
  AddFloatSetting(@Stop, 'Stop', 20);     //setting up stop in pips
  AddFloatSetting(@Amount, 'Amount(Lots)', 1);   //the Original number of lots
  AddIntegerSetting(@TraderRange, 'Trader Range', 0);   //setting up the trader range in pips
  AddAccountSetting(@Account, 'Account', '');    //the account number

  MACD := TIndicatorMACD.Create(History, 'MACD');   //creating the MACD indicator
  MACD.PeriodShorterEMA := 12;     
  MACD.PeriodLongerEMA := 26;
  MACD.PeriodForSignal := 9;   //setting up the MACD indicator periods
end;

/////////////////////////////////////////////////////////////////////////// 

procedure OnStart; 
begin

  Point := History.Instrument.PointSize;

  AmountOrig:=Amount;

end;

/////////////////////////////////////////////////////////////////////////// 

// this procedure runs when a new candle opens
procedure OnNewCandle;
begin
Point := History.Instrument.PointSize;

// if the MACD rises above its Signal line
if (MACD.Graph.Last(1) > MACD.SignalGraph.Last(1))
  and (MACD.Graph.Last(2) < MACD.SignalGraph.Last(2)) then
         begin
         // output the message into the log
         log ('The MACD crossed the Signal line bottom-up. A Buy position opened.');
         // open a Buy position
         CreateOrder(History.Instrument, Account, Amount, bsBuy,
                     History.Instrument.Sell - Point*Stop,
                     History.Instrument.Sell + Point*Limit, TraderRange, 'MACDTrade');
         end;
                   
// if the MACD falls below its Signal line
if (MACD.Graph.Last(1) < MACD.SignalGraph.Last(1))
  and (MACD.Graph.Last(2) > MACD.SignalGraph.Last(2)) then
         begin
         // output the message into the log
         log ('The MACD crossed the Signal line top-down. A Sell position opened.');                  
         // open a Sell position
         CreateOrder(History.Instrument, Account, Amount, bsSell,
                     History.Instrument.Buy + Point*Stop,
                     History.Instrument.Buy - Point*Limit, TraderRange, 'MACDTrade');
         end;
end;

// this procedure runs when some changes occur in the Open Positions list
procedure OnTradeChange(const Action: TDataModificationType; const Trade: TTrade);
begin
// if a new trade opened
if Action=dmtInsert then
  begin
  // output the trade information into the log
    log('Instrument: ' +Trade.Instrument.Name);
    log('Account: ' +Trade.Account.Id);
    log('Amount: ' +FloatToStr(Trade.Amount));
    log('Open rate: ' +FloatToStr(Trade.OpenRate));
  end;

if (Action=dmtDelete) then
begin

  Amount:=Trade.Account.Balance/Regulator;
  Amount:=Trunc(Amount);
  if (Amount < AmountOrig) then
  begin
    Amount:=AmountOrig;
  end;

end;

end;
      

Edited: 8/29/2010 11:22:38 AM by black
Post #1907
« 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:51am


© 2009 Actforex.com Terms of Use