Forex



Go Back   Forex Trading > Programming > Metatrader Programming






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

Reply
 
Thread Tools Display Modes
  #1081 (permalink)  
Old 07-07-2008, 02:47 AM
Senior Member
 
Join Date: Feb 2007
Posts: 985
FerruFx is on a distinguished road
Quote:
Originally Posted by bdht View Post
Hi, Everyone.

Recently I was trying to make a simple EA that would work on an arrow-based indicator. I am trying to make the EA to maintain one order at any given time. If the arrow points down, the previous buy order is closed and sell order is opened. If the arrow points up, the previous sell order is closed and buy order is opened. I am using the tester (visualization mode) to verify my code. It seems that no matter how I try, the EA does not close and open the positions when arrow indicator points up or down. The back test confirms that the EA is not working properly. Instead of opening and closing the orders at the arrow points shown by the indicator, the EA closes/opens order at some different time. I cannot understand why my code doesn't work.

In the beginning of start statement, I have the following code:

if (Time[0] == savedTime) {
return (0);
} else {
savedTime = Time [0];
}

This (I hope) will ensure that the code in the start statement is executed only when new bar has formed. Later in the body of the start subroutine, I query the indicator with iCustom function. The request looks as below:

iCustom (... 1)

The last argument of one specifies the previous formed bar, which is why it is not 0. Yet later I close the opened order with OrderClose and open new one with OrderSend. I suppose that both functions must be able to execute instantaneously.

The bottom line is: I am trying to create an EA based on arrow indicator. The indicator points either up or down. The way I see it (and I am probably incorrect), the only thing that I need to do is to close previous order and open new one when the next bar has formed. I would greatly appreciate any input into this problem.

Thanks to all.
If you look at your signal only once a bar and your "system" close and reverse when the signal change, it's important to check for exit BEFORE check for entry. If not, when a new entry signal is there, the EA can't enter the trade because the previous one is still open. And when the EA close the position, it will enter only at the next bar because it come in this part of code only once a bar.

Hope that make sense (with my english!).

FerruFx
__________________
FerruFx / www.ervent.net - Professional Coding Services (EAs/Indicators/Alerts)

BBVPS.com - Reliable Windows VPS For MT4 Hosting
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1082 (permalink)  
Old 07-07-2008, 07:45 AM
Administrator
 
Join Date: Sep 2005
Posts: 20,017
Blog Entries: 235
newdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud of
Quote:
Originally Posted by Dave137 View Post
Can somebody refresh my mind on how to get 2-indicators on one seperate window so they overlap each other??

Thanks for you assistance in advance!

Dave
Look at this page: filters indicators
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1083 (permalink)  
Old 07-07-2008, 04:44 PM
nondisclosure007's Avatar
Senior Member
 
Join Date: Apr 2007
Posts: 123
nondisclosure007 is on a distinguished road
Well, this will fix your new bar problem (got it from an article out at mql4.com):
Code:
bool funcIsNewBar()
   {
   bool res=false;
   
   // the array contains open time of the current (zero) bar
   // for 7 (seven) timeframes
   static datetime _sTime[7];  
   int i=6;
   int timeFrame = Period();
   
   switch (timeFrame) 
      {
      case 1  : i=0; break;
      case 5  : i=2; break;
      case 15 : i=3; break;
      case 30 : i=4; break;
      case 60 : i=5; break;
      case 240: i=6; break;
      case 1440:break;
      default:  timeFrame = 1440;
      }
//----
   if (_sTime[i]==0 || _sTime[i]!=iTime(Symbol(),timeFrame,0))
      {
      _sTime[i] = iTime(Symbol(),timeFrame,0);
      res=true;
      }
      
//----
   return(res);   
   }
Call this function like this
Code:
int start()
{
     if (funcIsNewBar)
     {
          //run some code
     }
     return (0);
}
That'll get code to run ONLY when there is a new bar.

What you need to do is find out in the data window of MT4 what the values are when there is NO arrow being put on the chart by your indicator. For example, the indicator may may have 0's or may be blank.

So all you do then is call the value of the indicator at each open
Code:
varMyIndieValue=iCustom(<blah blah>);
if (varMyIndieValue>0) //there's an arrow
{ 
     //run some code
}


Quote:
Originally Posted by bdht View Post
Hi, Everyone.

Recently I was trying to make a simple EA that would work on an arrow-based indicator. I am trying to make the EA to maintain one order at any given time. If the arrow points down, the previous buy order is closed and sell order is opened. If the arrow points up, the previous sell order is closed and buy order is opened. I am using the tester (visualization mode) to verify my code. It seems that no matter how I try, the EA does not close and open the positions when arrow indicator points up or down. The back test confirms that the EA is not working properly. Instead of opening and closing the orders at the arrow points shown by the indicator, the EA closes/opens order at some different time. I cannot understand why my code doesn't work.

In the beginning of start statement, I have the following code:

if (Time[0] == savedTime) {
return (0);
} else {
savedTime = Time [0];
}

This (I hope) will ensure that the code in the start statement is executed only when new bar has formed. Later in the body of the start subroutine, I query the indicator with iCustom function. The request looks as below:

iCustom (... 1)

The last argument of one specifies the previous formed bar, which is why it is not 0. Yet later I close the opened order with OrderClose and open new one with OrderSend. I suppose that both functions must be able to execute instantaneously.

The bottom line is: I am trying to create an EA based on arrow indicator. The indicator points either up or down. The way I see it (and I am probably incorrect), the only thing that I need to do is to close previous order and open new one when the next bar has formed. I would greatly appreciate any input into this problem.

Thanks to all.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1084 (permalink)  
Old 07-07-2008, 05:16 PM
Member
 
Join Date: Sep 2007
Posts: 69
Ronald Raygun is on a distinguished road
Manage Multiple trades

Hey all,

I'm trying to develop an EA which can theoretically enter an infinite amount of trades, and manage for each trade the:
  1. Trailing Stop
  2. Move to BE
  3. ATR-Trailing Stop
  4. etc

I know EAs like swiss army and manageTP can do this. I don't know how.

Any suggestions?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1085 (permalink)  
Old 07-16-2008, 12:44 PM
Member
 
Join Date: Jun 2006
Posts: 44
rarango is on a distinguished road
need help writing code for stoping trading after a loss

Hi,

I need to write code so that an expert stops trading for a specific number of hours after one loss or after two or three consecutive losses.

can some body help me?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1086 (permalink)  
Old 07-21-2008, 05:00 AM
Junior Member
 
Join Date: Jan 2007
Posts: 4
jawas_ftsm is on a distinguished road
Coding for Martinggle with hedging closed

Hi Team,

i would like to seek a code that can provide me to the solution of my stategies below;

examples;
martingle concept-
TP = 23 pips
Pip gaps = 20
OP buy EU 0.1,0.2,0.4,0.8,1.6 lot
1. if layer on lot 1,6 floating more than -20pips then OP Sell EU with 12.8lot (tp 23).
2. if layer 12.8 lot hit TP close all EU position.
3. if 12.8 lot pip=0 then close position on Sell EU only.
4. repeat situation 1 until 3 again if the condition apply.

Need your favour to advise me on the function and codes.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1087 (permalink)  
Old 07-22-2008, 10:05 PM
Member
 
Join Date: May 2008
Posts: 57
fireslayer26 is on a distinguished road
coding question

Right now this code works by checking to see if the current opening is higher than the previous bar. My question is how would I change it if I wanted it to see if it was higher OR EQUAL TO the previous bar?

if(Open[0] > Open[0+1] &&
Open[0+1] > Open[0+2] &&
Open[0+2]> Open[0+3] &&
Open[0+3] > Open[0+4] &&
Open[0+4] > Open[0+5] &&
Open[0+5] > Open[0+6]) Order = SIGNAL_SELL

Would I just add a = next to the greater than sign, like this = >?

Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1088 (permalink)  
Old 07-22-2008, 10:25 PM
Junior Member
 
Join Date: Jun 2008
Posts: 13
oneg is on a distinguished road
try this:

Code:
if(Open[0] => Open[0+1] &&
Open[0+1] => Open[0+2] &&
Open[0+2]=> Open[0+3] &&
Open[0+3] => Open[0+4] &&
Open[0+4] => Open[0+5] &&
Open[0+5] => Open[0+6]) Order = SIGNAL_SELL
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1089 (permalink)  
Old 07-22-2008, 10:31 PM
cooltrader28@yahoo.com's Avatar
Member
 
Join Date: Dec 2007
Posts: 62
cooltrader28@yahoo.com is on a distinguished road
reverse expert advisor signals

hi

just playing around with this expert advisor

Code:
#property copyright "FORTRADER.RU"
#property link      "http://FORTRADER.RU"
 
/*
 
????????? ???????? ?????????? ????????? ???????? ? ?????? ??????? ?? 26 ??? 2008, 
??????????? ? ?????? ?? ????? ???? ?????? ? ????? ????????????: letters@fortrader.ru
http://www.fortrader.ru/arhiv.php
 
A detailed description of the parameters adviser available issue of the journal dated May 26 2008, 
suggestions and feedback we will be glad to see in our e-mail: letters@fortrader.ru
http://www.fortrader.ru/arhiv.php
 
*/
 
 
 
 
extern string x="????????? MACD:";
extern int FastEMA = 12;
extern int SlowEMA = 24;
 int SignalEMA = 9;
extern int predel = 6;
extern string x1="????????? MA:";
extern int SMA1 = 50;
extern int SMA2 = 100;
extern int otstup = 10; 
extern string x2="???????? ????? ??? ??????? ????-???? :";
extern int stoplossbars = 6;
extern string x3="??????????? ??? ??????? ?????? ?????? ? ???????? ???????? ???????:";
extern int pprofitum = 2;
extern string x4="?????? ?? ADX:";
extern int enable = 0;
extern int periodADX = 14;
 
extern double Lots=1;
 
datetime Bar;int buy,sell,i,a,b;double stoploss,setup2,adx,okbuy,oksell;
 
int start()
  {
 
     buy=0;sell=0;
     for(  i=0;i<OrdersTotal();i++)
         {
           OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
           if(OrderType()==OP_BUY){buy=1;}
           if(OrderType()==OP_SELL){sell=1;}
         }   
   
   //????????? ??????????
   double macd =iMACD(NULL,0,FastEMA,SlowEMA,SignalEMA,PRICE_CLOSE,MODE_MAIN,1);
   double sma1 =iMA(NULL,0,SMA1,0,MODE_SMA,PRICE_CLOSE,1);
   double sma2 =iMA(NULL,0,SMA2,0,MODE_SMA,PRICE_CLOSE,1);
   
   if(Close[1]<sma2){okbuy=1;}
    if(Close[1]>sma2){oksell=1;}
    
   if(enable==1)
   {
   adx=iADX(NULL,0,14,PRICE_CLOSE,MODE_MAIN,0);
   }else{adx=60;}
   
   
 
  
  if(Close[1]+otstup*Point>sma1 && Close[1]+otstup*Point>sma2 && macd>0 && buy==0)
  {
  
      buy=0;
      for( i=predel;i>0;i--)
      {
      macd=iMACD(NULL,0,FastEMA,SlowEMA,SignalEMA,PRICE_CLOSE,MODE_MAIN,i);
      if(macd<0){buy=2;}
      }
   
      if(buy==2 && adx>50 && okbuy==1)
      {okbuy=0;
          double stoploss=Low[iLowest(NULL,0,MODE_LOW,stoplossbars,1)];
          OrderSend(Symbol(),OP_BUY,Lots,Ask,3,stoploss,0,0,16385,0,Green);
          a=0;
       }
   }
   
   if(Close[1]-otstup*Point<sma1 && Close[1]-otstup*Point<sma2 && macd<0 && sell==0)
  {
  
      sell=0;
      for( i=predel;i>0;i--)
      {
      macd=iMACD(NULL,0,FastEMA,SlowEMA,SignalEMA,PRICE_CLOSE,MODE_MAIN,i);
      if(macd>0){sell=2;}
      }
   
      if(sell==2 && adx>50 && oksell==1)
      {oksell=0;
        
           stoploss=High[iHighest(NULL,0,MODE_HIGH,stoplossbars,1)];
          OrderSend(Symbol(),OP_SELL,Lots,Bid,3,stoploss,0,0,16385,0,White);
          b=0;
       }
   }
   
   
   if(buy==2 || buy==1)
   {
    for( i=0;i<OrdersTotal();i++)
         {
           OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
          
           
           if(OrderType()==OP_BUY )
           {  
           double setup2=OrderOpenPrice()+((OrderOpenPrice()-OrderStopLoss())*pprofitum);
 
            if(Close[1]>setup2 && a==0)
            {
             OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,White);
              OrderClose(OrderTicket(),OrderLots()/2,Bid,3,Violet); 
             
              a=1;
            }
            
            if(a==1 && sma1> Close[1]-otstup*Point)
            {
            OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); 
            }
            
           
           }
      }  
        
  }    
  
           if(sell==2 || sell==1)
   {
    for( i=0;i<OrdersTotal();i++)
         {
           OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
           
           
           if(OrderType()==OP_SELL )
           {  
            setup2=OrderOpenPrice()-((OrderStopLoss()-OrderOpenPrice())*pprofitum);
 
            if(Close[1]<setup2 && b==0)
            {
             OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,White);
              OrderClose(OrderTicket(),OrderLots()/2,Ask,3,Violet); 
              b=1;
            }
            
            if(b==1 && Close[1]-otstup*Point> sma1)
            {
            OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); 
            
            }
            
           
           }
      } 
      }
  
    
   
   
   
 
   return(0);
  }

how do i reverse the buy and sell orders ... cant get it working
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #1090 (permalink)  
Old 07-22-2008, 10:52 PM
Linuxser's Avatar
User Root
 
Join Date: May 2006
Location: Helliconia (Winter)
Posts: 4,407
Blog Entries: 56
Linuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond repute
To just inverse change OP_BUY with OP_SELL and the inverse action in the right codeline.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks

Tags
#include, candle time, CHinGsMAroonCLK, code, coders guru, conditionally, dll, eli hayun, Eur_harvester.ex4, expert adviser, expert advisor, forex, higher high, how to code, indicator, I_XO_A_H, kehedge, mechanical trading, metatrader command line, mt4, MT4-LevelStop-Reverse, OrderReliable.mqh, programming, rectangle tool, trading, volty channel stop

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to code this? iscuba11 Metatrader 4 mql 4 - Development course 1 08-03-2007 05:22 PM


All times are GMT. The time now is 06:25 PM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.