missing entries?

 

i dont really know programming of any kind but reading thru the material in the help section i came up with a simple program to practice different things for a EA.

the one im trying right now however doesnt seem to be working as it returns a few warnings for things that "should" be in the EA but arnt in because they arnt used in this one, but basicly i am trying to have it keep 1 ticket open of the currency pair its on as long as there isnt a ticket open for that currency already, which ended up looking like this:

//Buying
int longs=CountLongs();
SwapCal();
if (longs==0)
{
OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,StopLong(Ask,StopLoss),TakeLong(Ask,TakeProfit),NULL,0,0,Yellow);
}
return(0);
}
//+------------------------------------------------------------------+

cant tell if im missing anything but the problem its having is that alot of times it wont enter a trade for quite a while, one pair so far hasnt opened in 4 days since i started the bot on its chart. it also repeats this problem after closing a trade where alot of times it wont re-enter for a very longtime if at all( wont know the "if at all part for a while, as i cant live eternally to actually know that). it also sometimes shuts down with no error or message log to say why its closing, and sometimes disables the EA properties menu till i remove and reactivate it on the chart. i can post the rest of the code if u need, just didnt want to clutter up the first box.

 
wargumbyx wrote >>

i dont really know programming of any kind but reading thru the material in the help section i came up with a simple program to practice different things for a EA.

the one im trying right now however doesnt seem to be working as it returns a few warnings for things that "should" be in the EA but arnt in because they arnt used in this one, but basicly i am trying to have it keep 1 ticket open of the currency pair its on as long as there isnt a ticket open for that currency already, which ended up looking like this:

//Buying
int longs=CountLongs();
SwapCal();
if (longs==0)
{
OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,StopLong(Ask,StopLoss),TakeLong(Ask,TakeProfit),NULL,0,0,Yellow);
}
return(0);
}
//+------------------------------------------------------------------+

cant tell if im missing anything but the problem its having is that alot of times it wont enter a trade for quite a while, one pair so far hasnt opened in 4 days since i started the bot on its chart. it also repeats this problem after closing a trade where alot of times it wont re-enter for a very longtime if at all( wont know the "if at all part for a while, as i cant live eternally to actually know that). it also sometimes shuts down with no error or message log to say why its closing, and sometimes disables the EA properties menu till i remove and reactivate it on the chart. i can post the rest of the code if u need, just didnt want to clutter up the first box.

here is the whole code so far.

//+------------------------------------------------------------------+
//| Swap Bot.mq4 |
//| Tom the Great |
//| None |
//+------------------------------------------------------------------+
#property copyright "Tom the Great"
#property link "None"

//+------------------------------------------------------------------+
//| variables and things of that nature |
//+------------------------------------------------------------------+
extern int Account=0;

extern double Lots=0.01;
extern int Slippage=0;
extern int TakeProfit=0;
extern int StopLoss=0;
extern double Amount=0;
extern int TrailingStop=0;

bool runnable=true;
bool init=true;

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//Init
if(init==true)
{
init=false;
}//Init

//Buying
int longs=CountLongs();
SwapCal();
if (longs==0)
{
OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,StopLong(Ask,StopLoss),TakeLong(Ask,TakeProfit),NULL,0,0,Yellow);
}
return(0);
}
//+------------------------------------------------------------------+

double StopLong(double price, int stop)
{
if(stop==0)
return(0.0);
return(price-(stop*Point));
}

double StopShrt(double price, int stop)
{
if(stop==0)
return(0.0);
return(price+(stop*Point));
}

double TakeLong(double price, int take)
{
if(take==0)
return(0.0);
return(price+(take*Point));
}

double TakeShrt(double price, int take)
{
if(take==0)
return(0.0);
return(price-(take*Point));
}

void CloseLongs()
{
int trade;
int trades=OrdersTotal();
for(trade=0;trade<trades;trade++)
{
OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol()!=Symbol())
continue;

if(OrderType()==OP_BUY)
OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Blue);

}//for
}

void CloseShrts()
{
int trade;
int trades=OrdersTotal();
for(trade=0;trade<trades;trade++)
{
OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol()!=Symbol())
continue;

if(OrderType()==OP_SELL)
OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Blue);
}//for
}

void TrailingAlls(int trail)
{
if(trail==0)
return;

double stopcrnt;
double stopcal;

int trade;
int trades=OrdersTotal();
for(trade=0;trade<trades;trade++)
{
OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol()!=Symbol())
continue;

//Long
if(OrderType()==OP_BUY)
{
stopcrnt=OrderStopLoss();
stopcal=Bid-(trail*Point);
if(stopcrnt==0)
{
OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Blue);
}
else
{
if(stopcal>stopcrnt)
{
OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Blue);
}
}
}//Long

//Shrt
if(OrderType()==OP_SELL)
{
stopcrnt=OrderStopLoss();
stopcal=Ask+(trail*Point);
if(stopcrnt==0)
{
OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Red);
}
else
{
if(stopcal<stopcrnt)
{
OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Red);
}
}
}//Shrt
}//for
}

// Swap Calculator
void SwapCal()
{
double profit=OrderProfit();
double trade;
double trades=OrderSwap()/(-Amount);
for(trade=0;trades>profit;trade++)
{
OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol()!=Symbol())
continue;
//Closes Longs
if(OrderType()==OP_BUY&&trades<OrderProfit())
OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Blue);

}//for
}

//+------------------------------------------------------------------+
//| Calculate concurrent Long position |
//+------------------------------------------------------------------+
int CountLongs()
{
int count=0;
int trade;
int trades=OrdersTotal();
for(trade=0;trade<trades;trade++)
{
OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);

if( OrderSymbol()!=Symbol())
continue;

if(OrderType()==OP_BUY&&OrderSymbol()==Symbol())
count++;
}//for
return(count);
}

Reason: