Ctrade - trade.sell

 

Good day all, 

I am seeking to create trade deal task but instead of opening 1 single deal it opens many of them at the same time? Can anyone provide a suggestion? Not sure what I am missing here. Thank you 


#include<Trade\Trade.mqh>

CTrade trade;

MqlTradeRequest;

MqlTradeResult;

void OnTick()

{

double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);

double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);

double Balance=AccountInfoDouble(ACCOUNT_BALANCE);

double Equity=AccountInfoDouble(ACCOUNT_EQUITY);

if (Equity>= Balance)

trade.Sell(0.01,_Symbol,Ask,(Ask+75 * _Point),(Bid-125 * _Point),NULL);

}

 

Hi Coolze36, you entry is at:

1. an OnTick() event which is triggered on every tick ( I suggest you write a separate function then call it through onTick() 

2. Your if statement condition is mostly always true then when true on every tick there will a trade. (so if you need one trade at a time add PositionsTotal() on your if statement) like..

if (Equity>= Balance && PositionsTotal()==0)

trade.Sell(0.01,_Symbol,Ask,(Ask+75 * _Point),(Bid-125 * _Point),NULL);

}

Then your trade will enter once then another just after the other closes.

NB: I think you need a better strategy to enter trade than relying on the balance and account Equity.

Hope the above helps.

 
Coolze36:

Good day all, 

I am seeking to create trade deal task but instead of opening 1 single deal it opens many of them at the same time? Can anyone provide a suggestion? Not sure what I am missing here. Thank you 


#include<Trade\Trade.mqh>

CTrade trade;

MqlTradeRequest;

MqlTradeResult;

void OnTick()

{

double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);

double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);

double Balance=AccountInfoDouble(ACCOUNT_BALANCE);

double Equity=AccountInfoDouble(ACCOUNT_EQUITY);

if (Equity>= Balance)

trade.Sell(0.01,_Symbol,Ask,(Ask+75 * _Point),(Bid-125 * _Point),NULL);

}

Try to add this :

  if(entry=="sell" && PositionsTotal()< n)

      trade.Sell(0.05,NULL,Bid,0,(Bid-100 * _Point),NULL);

Fill n with number of deal as you want (1,2.3,....)....

 
trade.Sell(0.01,_Symbol,Ask,(Ask+75 * _Point),(Bid-125 * _Point),NULL);

You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.

  1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

  2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close to a specific Bid price, add the average spread.
              MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

  3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)

    Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes.
    My GBPJPY shows average spread = 26 points, average maximum spread = 134.
    My EURCHF shows average spread = 18 points, average maximum spread = 106.
    (your broker will be similar).
              Is it reasonable to have such a huge spreads (20 pip spreads) in EURCHF? - General - MQL5 programming forum (2022)

Reason: