|
|||||||
| Register in Forex TSD! | |
|
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time). Click here to register and get more information |
|
![]() |
|
|
LinkBack (1) | Thread Tools | Display Modes |
|
||||
|
Quote:
Code:
int BuyCnt = 0;
int SellCnt = 0;
int BuyStopCnt = 0;
int SellStopCnt = 0;
int BuyLimitCnt = 0;
int SellLimitCnt = 0;
int cnt = OrdersTotal();
for (int i=0; i < cnt; i++)
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
//if (OrderSymbol() != Symbol()) continue;
//if (OrderMagicNumber() != Magic) continue;
int type = OrderType();
if (type == OP_BUY) BuyCnt++;
if (type == OP_SELL) SellCnt++;
if (type == OP_BUYSTOP) BuyStopCnt++;
if (type == OP_SELLSTOP) SellStopCnt++;
if (type == OP_BUYLIMIT) BuyLimitCnt++;
if (type == OP_SELLLIMIT) SellLimitCnt++;
}
__________________
MQL4: idea * experience + creative solution |
|
||||
|
Quote:
Code:
extern int Magic = ...
//-----
int BuyCnt = 0;
int SellCnt = 0;
int cnt = OrdersTotal();
for (int i=0; i < cnt; i++)
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
if (OrderSymbol() != Symbol()) continue;
if (OrderMagicNumber() != Magic) continue;
int type = OrderType();
if (type == OP_BUY) BuyCnt++;
if (type == OP_SELL) SellCnt++;
}
if (BuyCnt+SellCnt < 8) return;
//-----
datetime tm = 0;
int ticket = -1;
cnt = OrdersTotal();
for (i=0; i < cnt; i++)
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
if (OrderSymbol() != Symbol()) continue;
if (OrderMagicNumber() != Magic) continue;
type = OrderType();
if (type == OP_BUY || type == OP_SELL)
{
if (OrderOpenTime() > tm)
{
tm = OrderOpenTime();
ticket = OrderTicket();
}
}
}
//-----
if (ticket != -1) OrderClose(ticket, ...
__________________
MQL4: idea * experience + creative solution |
|
||||
|
Quote:
Code:
#define OP_BALANCE 6
int cnt = OrdersHistoryTotal();
for (int i=0; i<cnt; i++)
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
if (OrderType() == OP_BALANCE)
{
Alert(OrderProfit());
break;
}
}
![]()
__________________
MQL4: idea * experience + creative solution |
|
|||
|
exiting a trade
Lets say I am in a trade based on a stochastic setting. I want to exit based on another stochastic cross totally different from my entry. No problem yet. But lets say at my exit the market continues to go up. I want to change the exit based on 95% of the current stochastic signal line to the next level to keep me in the trade. So once I have my current stochastic setting at 95% and it gets hit, my new exit is 95% of the new setting and once this gets hit my new exit is 95% of that setting. This setup can keep you in a trade until the market peaks and turns down crossing the signal and the trade is exited on the cross. You know when it seems overbought or oversold. By changing the stochastic settings, as the price increases you are able to stay in the market till the trend breaks. Once trade is closed, you start next order with 1st level of settings. Currently I use a main signal on one setting crossing a signal signal on another setting. I only use 1 of the lines each stoch and black the other one out. I want to be able to move at least 4 levels up if the market continues to trend. Of course the opposite would be for a sell.
|
|
||||
|
Quote:
Code:
extern double Lots = 0.1;
extern double MinLot = 0.1;
extern double MaxLot = 5.0;
extern int LotPrec = 1;
extern bool DynamicLot = false;
extern double LotStep = 0.1;
extern double BalanceStep = 500;
double GetLots()
{
double lots = Lots;
if (DynamicLot)
{
lots = NormalizeDouble(LotStep*AccountBalance()/BalanceStep, LotPrec);
}
lots = MathMax(lots, MinLot);
lots = MathMin(lots, MaxLot);
return (lots);
}
__________________
MQL4: idea * experience + creative solution |
|
|||
|
help EA
hello RickD
i try make simpel EA.... can u help me rick... sell: when price have 70pip range exampel : price open day : 208.55 low price(low price day) :208.30 and price going up (high price day)to 209.00 OP sell 209.00..... buy: when price have 70pip range exampel : price open day : 208.55 high price(high price day) :208.70 and price going down (low price day)to 207.00 OP buy 207.00..... thks RickD ![]() |
|
||||
|
Quote:
Do you mean that I should write the EA for you? Please send a PM me.
__________________
MQL4: idea * experience + creative solution |
|
||||
|
Quote:
Select the last order and don't trade some time. Code:
int MinTimeSec = 60; //no trade 60 seconds after last close
int Magic = ...
void start()
{
...
if (LastOrderSelect(MODE_HISTORY, OP_BUY, OP_SELL))
{
if (TimeCurrent() - OrderCloseTime() < MinTimeSec) return;
}
...
}
bool LastOrderSelect(int pool, int type1, int type2 = -1)
{
datetime tm = -1;
int ticket = -1;
if (pool == MODE_TRADES)
{
int cnt = OrdersTotal();
for (int i=0; i < cnt; i++)
{
if (!OrderSelect(i, SELECT_BY_POS, pool)) continue;
if (OrderSymbol() != Symbol()) continue;
if (OrderMagicNumber() != Magic) continue;
int type = OrderType();
if (type == type1 || type == type2)
{
if (OrderOpenTime() > tm)
{
tm = OrderOpenTime();
ticket = OrderTicket();
}
}
}
return (OrderSelect(ticket, SELECT_BY_TICKET));
}
if (pool == MODE_HISTORY)
{
cnt = OrdersHistoryTotal();
for (i=0; i < cnt; i++)
{
if (!OrderSelect(i, SELECT_BY_POS, pool)) continue;
if (OrderSymbol() != Symbol()) continue;
if (OrderMagicNumber() != Magic) continue;
type = OrderType();
if (type == type1 || type == type2)
{
if (OrderCloseTime() > tm)
{
tm = OrderCloseTime();
ticket = OrderTicket();
}
}
}
return (OrderSelect(ticket, SELECT_BY_TICKET));
}
return (false);
}
__________________
MQL4: idea * experience + creative solution |
|
|||
|
Alert question
Hi
I wrote Alert but it only works when I open window with my indicator. It works only also when I jump beetwen charts windows, in other words when I jump between charts time levels. It seems that indicator can not count when whorks. How can I solve my problem ? Need help. Is it conected with Indicatorcounted ? Should I do something in parameter of Alert. How to do it ? Should I use something like: double ? = ObjectGetValueByShift(string name, int shift)); if (???????????) Alert("Pattern on " + Symbol() + " " + Period()); Pucio |
|
|||
|
Crossing
Hey Rick, I'm glad you're doing this.
What's the code for crossing of two 2-line indicators? I'm sure it isn't really difficult. Say, the 1st indicator's lines cross each other 1 bar before [MAIN > SIGNAL] = BUY order, 2nd indicator's lines cross one another [MAIN < SIGNAL] = SELL order. What I came up with is this, but it just doesn't cut it. Code:
if (Time[0] == prevtime)
return(0);
prevtime = Time[0];
//IND1 = iIND1 (NULL, 0, 0, MODE_MAIN, 0); mentioned later
//IND1S = iIND1 (NULL, 0, 0, MODE_SIGNAL, 0); mentioned later
IND2 = iIND2 (NULL, 0, 0, MODE_MAIN, 0); // how to go about these two?
IND2S = iIND2 (NULL, 0, 0, MODE_SIGNAL, 0); // how to go about these two?
]Code:
int Crossed (double line1 , double line2)
{
static int last_direction = 0;
static int current_direction = 0;
if(line1>line2)current_direction = 1; //up
if(line1<line2)current_direction = 2; //down
if(current_direction != last_direction) //changed
{
last_direction = current_direction;
return (last_direction);
}
else
{
return (0);
}
}
IND1 = iIND1 (NULL, 0, 0, MODE_MAIN, 0);
IND1S = iIND1 (NULL, 0, 0, MODE_SIGNAL, 0);
int isCrossed = Crossed (IND1 ,IND2);
if(isCrossed == 1)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"My EA",12345,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Yikes! You're screwed! Get back to the manual!!! Ha! ",GetLastError());
return(0);
}
if(isCrossed == 2)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"My EA",12345,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
else Print(""Yikes! You're screwed! Get back to the manual!!! Ha! "",GetLastError());
return(0);
}
return(0);
}
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/metatrader-programming/7813-mql4-guide.html
|
|||
| Posted By | For | Type | Date |
| E2E-Fx | This thread | Refback | 08-17-2007 11:18 PM |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Welcome to the MQL4 course | codersguru | Metatrader 4 mql 4 - Development course | 81 | 03-22-2008 10:32 AM |
| Help for convert from VT to MQL4 | M-E-C | Expert Advisors - Metatrader 4 | 11 | 07-27-2007 06:53 PM |
| Arrays in MQL4 | clippertm | Questions | 4 | 04-12-2007 09:35 PM |
| www.mql4.com | DeSt | Metatrader 4 | 18 | 02-01-2006 11:59 PM |