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
unknown subwindow number
Hi fellow coders
Any one got a solution to this issue with iCustom calls, I have tried everything i can think of but still have the same message in the Experts tab.
unknown subwindow number -1 for ObjectCreate function
Regards CJA
Remove the subwindow calls in the Indicator
Hi fellow coders
Any one got a solution to this issue with iCustom calls, I have tried everything i can think of but still have the same message in the Experts tab.
unknown subwindow number -1 for ObjectCreate function
Regards CJAHi CJA,
I have a solution that I use to work around this problem.
The indicator your EA is calling in the iCustom is trying to find a subwindow to draw it's Objects.
In most cases you don't need your indicator drawing anything, just providing the indicator values to your EA.
My solution is to make a copy of the indicator and delete the subwindow calls and the Object drawing routines.
This eliminates the subwindow errors and makes the EA run faster as well.
Then use this new indicator name in your iCustom statements for your EA.
I'm sure there's probably a better code solution, but this works for me.
Hope this helps,
Robert
iCustom subwindow errors
Hi CJA,
I have a solution that I use to work around this problem.
The indicator your EA is calling in the iCustom is trying to find a subwindow to draw it's Objects.
In most cases you don't need your indicator drawing anything, just providing the indicator values to your EA.
My solution is to make a copy of the indicator and delete the subwindow calls and the Object drawing routines.
This eliminates the subwindow errors and makes the EA run faster as well.
Then use this new indicator name in your iCustom statements for your EA.
I'm sure there's probably a better code solution, but this works for me.
Hope this helps,
RobertThanks Robert - your suggestion works however I suspect there must be some other way of doing it although I did a search on the net and found no solutions that worked or made any sense just a lot of questions and no answers. So thanks for your help once more.
Regards CJA
CJA
Just a suggestion : why don't you use (when called with iCustom()) a parameter to pass the desired window number? Something like : if (ParameterWindowID>=0) then it is from iCustom else do some default code.
That way you could force it to draw objects even when called from another code and it would draw objects in a correct place
Help with Coding
Hi guys.
Please can anybody tell me if it is possible to use BOLD textFONTtype in email alert report? When yes how I can code this?
Thanks a lot for help.
Do you mean how to save to CSV file?
Check this:
Tools - .csv readerHi, Guru,
Is there anywhere on your website I could download this dll? I think this is an excellent tool and I'm pretty sure you can write it better than me so I won't bother with it. Thanks in advance.
Do I need to register? This is located under download section but I couldn't figure out how to download anything.
quick EA modification
Hi,
Need some help, I tried to change the code below but the EA kept crashing MT4.
I want the order to close when the current bar (so the bar where the order was executed) closes. Basically trade one bar.
This is the original code, it trades from signal to signal.
//| Signal Begin(Exit Buy) |
//+------------------------------------------------------------------+
if (signaldown!=EMPTY_VALUE&&signaldown!=0) Order = SIGNAL_CLOSEBUY;
//+------------------------------------------------------------------+
//| Signal End(Exit Buy) |
//+------------------------------------------------------------------+
if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
if (!EachTickMode) BarCount = Bars;
IsTrade = False;
continue;
}
//Trailing stop
if(UseTrailingStop && TrailingStop > 0) {
if(Bid - OrderOpenPrice() > Point * TrailingStop) {
if(OrderStopLoss() < Bid - Point * TrailingStop) {
OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
if (!EachTickMode) BarCount = Bars;
continue;
}
}
}
} else {
//Close
//+------------------------------------------------------------------+
//| Signal Begin(Exit Sell) |
//+------------------------------------------------------------------+
if (signalup!=EMPTY_VALUE&&signalup!=0) Order = SIGNAL_CLOSESELL;
//+------------------------------------------------------------------+
//| Signal End(Exit Sell) |
//+------------------------------------------------------------------+
if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
if (!EachTickMode) BarCount = Bars;
IsTrade = False;
continue;
}
//Trailing stop
if(UseTrailingStop && TrailingStop > 0) {
if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {
if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {
OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
if (!EachTickMode) BarCount = Bars;
continue;
}
}
}
}
}
}
//+------------------------------------------------------------------+
//| Signal Begin(Entry) |
//+------------------------------------------------------------------+
//if (timeprev!=Time[0]){
// timeprev = Time[0];
if (signalup!=EMPTY_VALUE&&signalup!=0)
{
Order = SIGNAL_BUY;
}
if (signaldown!=EMPTY_VALUE&&signaldown!=0){
Order = SIGNAL_SELL;
}
// }
//+------------------------------------------------------------------+
//| Signal End |
//+------------------------------------------------------------------+
//Buy
if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
if(!IsTrade) {
//Check free margin
if (AccountFreeMargin() < (100 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;
Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
if(Ticket > 0) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
Print("BUY order opened : ", OrderOpenPrice());
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
} else {
Print("Error opening BUY order : ", GetLastError());
}
}
if (EachTickMode) TickCheck = True;
if (!EachTickMode) BarCount = Bars;
return(0);
}
}
//Sell
if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
if(!IsTrade) {
//Check free margin
if (AccountFreeMargin() < (100 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}
if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;
Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
if(Ticket > 0) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
Print("SELL order opened : ", OrderOpenPrice());
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
} else {
Print("Error opening SELL order : ", GetLastError());
}
}
if (EachTickMode) TickCheck = True;
if (!EachTickMode) BarCount = Bars;
return(0);
}
}
if (!EachTickMode) BarCount = Bars;
return(0);
}
//+------------------------------------------------------------------+Can anyone help me out?
I also found this code,
if(data!=iTime(Symbol(),0,0))
{
if(signalup!=EMPTY_VALUE&&signalup!=0)
{
if(openpos()>0)
{
for(i=0;i<OrdersTotal();i++)
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()==OP_SELL&&OrderSymbol()==Symbol()&&OrderMagicNumber()==mn)
{
if(OrderClose(OrderTicket(),lots,Ask,slip))
Print("short was closed");
}
}
}
Print("try open long");
Print(Symbol());
nt=OrderSend(Symbol(),OP_BUY,lots,Ask,slip,0,0,"ab",mn,0,Green);
if(nt>0)
Print("long order was opened");
}
if(signaldown!=EMPTY_VALUE&&signaldown!=0)
{
if(openpos()>0)
{
for(i=0;i<OrdersTotal();i++)
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()==OP_BUY&&OrderSymbol()==Symbol()&&OrderMagicNumber()==mn)
{
if(OrderClose(OrderTicket(),lots,Bid,slip))
Print("long was closed");
}
}
}
Print("try open short");
Print(Symbol());
nt=OrderSend(Symbol(),OP_SELL,lots,Bid,slip,0,0,"ab",mn,0,Red);
if(nt>0)
Print("short was opened");
}
data=iTime(Symbol(),0,0);
}
//----
//----
return(0);
}
//+------------------------------------------------------------------+
int openpos()
{
int j=0;
int i,n;
n=OrdersTotal();
for(i=0;i<n;i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
if(OrderSymbol()==Symbol()&&OrderMagicNumber()==mn&&(OrderType()==OP_SELL||OrderType()==OP_BUY))
j++;
}
return(j);
Can any expert tell me which one is better written?
Breakeven for all orders of a pair (magic)
Hi all,
i want to collect all orders (buy&sell) of a pair by magic and if they reach a breakeven, all orders should be closed.
any guidance very welcome, thanks
extern bool PairBreakeven=true;// Breakeven per pair all orders of same pair/magic
extern double Pairbreakevengain=6;// gain in pips required to enable the break even
extern double Pairbreakeven=3;// break even, order closed, 3 pip profit/slippage
double Pairmovebreakeven;
if(PairBreakeven==true){
if(Pairbreakevengain>0)Pairmovebreakeven(Pairbreakevengain,Pairbreakeven);
CloseBuyOrders(Magic);
CloseSellOrders(Magic);
}
void Pairmovebreakeven(double Pairbreakevengain,double Pairbreakeven){
RefreshRates();
if(OrdersTotal()>0){
for(int i=OrdersTotal();i>=0;i++){
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic ){
return;
}
}
}
}
int CloseBuyOrders(int Magic){ //op_sell is similar
int total=OrdersTotal();
for(int cnt=total-1;cnt>=0;cnt--){
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderMagicNumber()==Magic && OrderSymbol()==Symbol()){
if(OrderType()==OP_BUY){
OrderClose(OrderTicket(),OrderLots(),Bid,3*mt);
}
}
}
return(0);
}
ArraySort with 3 or more dimensions.
Can any experts help in this?
I have tried using arraysort successfully for 1 or 2 dimension array. But got stuck with the 3 dimension. As far as i know arraysort uses only the first column for sorting. Can anyone advise on how to solve this arraysorting with 3 or more dimensions?
bool Restart = true;
double arraystore[20][20][20];
double ArrayActual[20] = {1.23,3.65,0.02,5.44,0.92,0.11,1.21,999.0,555.5,0.0001,44.221,1.01,0.002};
void init()
{
if (Restart == true)
{
Go();
Restart = false;
}
}
void start()
{
}
void Go()
{
for (int a = 1; a<=3; a++)
{
for (int b = 1; b<=6; b++)
{
int c = b+ (a-1)*6;
arraystore[a][0] = ArrayActual[c];
arraystore[a][1] = a;
arraystore[a][2] = b +a;
Print ( arraystore[a][0] + " . " + arraystore[a][1] + " . " + arraystore[a][2]);
}
}
ArraySort(arraystore,WHOLE_ARRAY,1,MODE_DESCEND);
for ( a = 1; a<=3; a++)
{
for ( b = 1; b<=6; b++)
{
Print ( arraystore[a][0] + " . " + arraystore[a][1] + " . " + arraystore[a][2]);
}
}
}