try counting the other way around in closing section
for(int cntB = OrdersTotal()-1; cntB>=0; cnt--)
nickbilak wrote >>
try counting the other way around in closing section
for(int cntB = OrdersTotal()-1; cntB>=0; cnt--)
doshur, your code looks right for me, maybe you must increase TradeProfit parameter to have more open trades to close.
So I suggest you put debug codes before any change, for example:
Print("Average BUY Close ",cntABC);
good lucky!
Try :
if(MA_Signal < MA_Main)
{
OrdersCount=OrdersTotal();
for(int cntB = 0; cntB < OrdersCount; cntB++)
{
................
i guess i stop writing EAs...
they don't seems to work my way...
anyone can programme for free? i share my strategy...
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
hi all,
i using averaging down tatics but i can't seem to close all my orders
anyone pls help.
//+------------------------------------------------------------------+
//| CrossHedgeAverage.mq4 |
//| doshur |
//| www.doshur.com |
//+------------------------------------------------------------------+
#property copyright "doshur"
#property link "www.doshur.com"
//---- input parameters
extern double StopLoss = 40;
extern double TradeProfit = 1;
//----
int init()
{
return(0);
}
int deinit()
{
return(0);
}
//---- Optimize Lots
double Check_Lots()
{
double rLots;
rLots = NormalizeDouble(AccountBalance() / 100 * 0.5 / 40,1); // account balance / margin * winning chance / stoploss
if(rLots > 5)
rLots = 5;
return(1);
}
//---- Check Open Trades
int Check_OpenTrades(int bs)
{
int buys = 0, sells = 0;
for(int c_OT = 0; c_OT < OrdersTotal(); c_OT++)
{
OrderSelect(c_OT, SELECT_BY_POS, MODE_TRADES);
if(OrderType() == OP_BUY)
buys++;
if(OrderType() == OP_SELL)
sells++;
}
if(bs == 1)
return(buys);
if(bs == 2)
return(sells);
}
//----
int start()
{
//---- General
double Spread;
double OrderPIPs;
static int AvgBuyCnt = 0;
static double AvgBuy = 0;
static double LastBuy = 0;
static bool AvgBuyClose = false;
Spread = (Ask - Bid) / Point;
//---- MACD
double MACD_Main, MACD_Signal;
MACD_Main = iMACD(NULL,0,10,22,9,PRICE_LOW,MODE_MAIN,0);
MACD_Signal = iMACD(NULL,0,10,22,9,PRICE_LOW,MODE_SIGNAL,0);
//---- MAs
double MA_Main, MA_Signal, Trend_Main, Trend_Signal;
MA_Main = iMA(NULL,0,12,1,MODE_SMA,PRICE_LOW,0);
MA_Signal = iMA(NULL,0,8,0,MODE_LWMA,PRICE_LOW,1);
Trend_Main = iMA(NULL,0,36,2,MODE_EMA,PRICE_LOW,0);
Trend_Signal = iMA(NULL,0,36,0,MODE_EMA,PRICE_LOW,0);
//---- BUY Open
int buys;
buys = Check_OpenTrades(1);
if(AvgBuyClose == false)
if(Trend_Signal > Trend_Main)
if(MACD_Main > MACD_Signal)
if(MA_Signal > MA_Main)
if(buys < 1)
{
//OrderSend(Symbol(),OP_BUY,Check_Lots(),Ask,3,Ask - StopLoss * Point,0,"doshur",0,0,Blue);
OrderSend(Symbol(),OP_BUY,Check_Lots(),Ask,3,0,0,"doshur",0,0,Blue);
AvgBuy = Ask;
LastBuy = AvgBuy;
AvgBuyCnt++;
}
//---- BUY Close
if(AvgBuyClose == false)
if(MACD_Main < MACD_Signal)
if(MA_Signal < MA_Main)
{
for(int cntB = 0; cntB < OrdersTotal(); cntB++)
{
OrderSelect(cntB, SELECT_BY_POS, MODE_TRADES);
if(OrderType() == OP_BUY)
{
OrderPIPs = (Bid - OrderOpenPrice()) / Point;
if(OrderPIPs > Spread + TradeProfit)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
AvgBuy = 0;
LastBuy = 0;
AvgBuyCnt = 0;
}
}
}
}
//---- Average BUY Open
if(AvgBuyCnt > 0)
{
OrderPIPs = (LastBuy - Bid) / Point;
if(OrderPIPs > StopLoss)
{
OrderSend(Symbol(),OP_BUY,Check_Lots(),Ask,3,0,0,"doshur",0,0,Blue);
LastBuy = Ask;
AvgBuy = ((AvgBuy * AvgBuyCnt) + LastBuy) / (AvgBuyCnt + 1);
AvgBuyCnt++;
AvgBuyClose = true;
}
}
//---- Average BUY Close
if(AvgBuyClose == true)
if(Bid > AvgBuy)
{
for(int cntABC = 0; cntABC < OrdersTotal(); cntABC++)
{
OrderSelect(cntABC, SELECT_BY_POS, MODE_TRADES);
if(OrderType() == OP_BUY)
OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
}
AvgBuy = 0;
LastBuy = 0;
AvgBuyCnt = 0;
AvgBuyClose = false;
}
//----
return(0);
}
//+------------------------------------------------------------------+