Forex
Google
New signals service!

Go Back   Forex Trading > Metatrader Training > Metatrader 4 mql 4 - Development course > Questions


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
 
LinkBack (2) Thread Tools Display Modes
  #1021 (permalink)  
Old 03-31-2008, 09:18 PM
Senior Member
 
Join Date: Feb 2006
Posts: 559
Michel is on a distinguished road
Quote:
Originally Posted by ableze_joepardy View Post
hi.. I've modified the default script (trade.mq4) in metatrader platform to execute martingle based trade.. the condition is like below:

Starting lot: 0.1
Multiple: 2
Pips: 8
TP: 10
Max trade: 5

and here's the code..

Code:
//+------------------------------------------------------------------+
//|                                                    buy 1 lot.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#include <stdlib.mqh>
#include <WinUser32.mqh>
//+------------------------------------------------------------------+
//| script "trading for all money"                                   |
//+------------------------------------------------------------------+
int start()
  {
//----
   if(MessageBox("Do you really want to execute Martingle "+Symbol()+" at ASK price?    ",
                 "Script",MB_YESNO|MB_ICONQUESTION)!=IDYES) return(1);
//----
   int ticket1=OrderSend(Symbol(),OP_BUY,0.1,Ask,3,Ask-40*Point,Ask+10*Point,"GU M5",770,0,CLR_NONE);
   int ticket2=OrderSend(Symbol(),OP_BUYLIMIT,0.2,Ask-8*Point,3,Ask-40*Point,Ask+2*Point,"GU M5",770,0,CLR_NONE);
   int ticket3=OrderSend(Symbol(),OP_BUYLIMIT,0.4,Ask-16*Point,3,Ask-40*Point,Ask-6*Point,"GU M5",770,0,CLR_NONE);
   int ticket4=OrderSend(Symbol(),OP_BUYLIMIT,0.8,Ask-24*Point,3,Ask-40*Point,Ask-14*Point,"GU M5",770,0,CLR_NONE);
   int ticket5=OrderSend(Symbol(),OP_BUYLIMIT,1.6,Ask-32*Point,3,Ask-40*Point,Ask-22*Point,"GU M5",770,0,CLR_NONE);
   if(ticket1<1)
     {
      int error1=GetLastError();
      Print("Error = ",ErrorDescription(error1));
      return;
     }
   if(ticket2<1)
     {
      int error2=GetLastError();
      Print("Error = ",ErrorDescription(error2));
      return;
     }
   if(ticket3<1)
     {
      int error3=GetLastError();
      Print("Error = ",ErrorDescription(error3));
      return;
     }
   if(ticket4<1)
     {
      int error4=GetLastError();
      Print("Error = ",ErrorDescription(error4));
      return;
     }
   if(ticket5<1)
     {
      int error5=GetLastError();
      Print("Error = ",ErrorDescription(error5));
      return;
     }        
//----
   OrderPrint();
   return(0);
  }
//+------------------------------------------------------------------+
but the code didnt execute the order.. whats wrong with the code?
What is the returned error ? You also should numbered the error messages, but take care that if you have two errors, for example on order 2 and 5, you will display for the order 2 the error of the order 5.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1022 (permalink)  
Old 03-31-2008, 09:41 PM
Junior Member
 
Join Date: Feb 2008
Posts: 7
ableze_joepardy is on a distinguished road
Quote:
Originally Posted by Michel View Post
What is the returned error ? You also should numbered the error messages, but take care that if you have two errors, for example on order 2 and 5, you will display for the order 2 the error of the order 5.
edited:

sorry.. i think the error is displayed in Expert window rite? And this is what I got after renaming the Error from 1 - 5...

error.GIF

Last edited by ableze_joepardy; 03-31-2008 at 09:47 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1023 (permalink)  
Old 03-31-2008, 10:23 PM
Senior Member
 
Join Date: Feb 2006
Posts: 559
Michel is on a distinguished road
Quote:
Originally Posted by ableze_joepardy View Post
edited:

sorry.. i think the error is displayed in Expert window rite? And this is what I got after renaming the Error from 1 - 5...

Attachment 58175
You have the error " trade not allowed in the expert properties"
So hit ctrl-O, then tab "Expert Avisors" and select "Allow live trading"

BTW, renaming the variables will not erase the possibility of false information, you also need to check the error after each OrderSend() call and before the next one.

Last edited by Michel; 03-31-2008 at 10:29 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1024 (permalink)  
Old 03-31-2008, 10:39 PM
Junior Member
 
Join Date: Feb 2008
Posts: 7
ableze_joepardy is on a distinguished road
owh thank you michel..

btw.. got another question.. ive also modified the mt4 default script to check if any trades opened using script above reach +10 pips.. If got any then close all 5 orders..

example..

Trade 1 lost
Trade 2 lost
Trade 3 +10 pips
Trade 4 Pending
Trade 5 Pending

then close all trades n delete all pending orders with magic no. 770..

can u please check whether the script below will do the job as planne?

Code:
//+------------------------------------------------------------------+
//|                                         AutoClose Same Magic.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

int cnt;
double CurrentProfit;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+

void CloseAllOrders(double MN) {
   bool   result;
   double price;
   int    cmd,error;
  
   while (OrdersTotal() > 0) {
      // Loop through all orders and close them
      for (int i = (OrdersTotal() - 1); i >= 0; i--) {
         if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) {
            if (OrderMagicNumber() == MN) {
               cmd = OrderType();
               if (cmd == OP_BUY) {
               OrderClose(OrderTicket(),OrderLots(),Bid,3,CLR_NONE);
               }
               else if (cmd != OP_BUY && cmd != OP_SELL) {
               OrderDelete(OrderTicket());
               }
            }
         }
      }
   }
}

int start()
  {
//----

for(cnt=OrdersTotal();cnt>=0;cnt--)
      {
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if( OrderMagicNumber()==770 )
            {
               if(OrderType()==OP_BUY)
                  {
                     CurrentProfit=Bid-OrderOpenPrice() ;
                     if(CurrentProfit>10*Point)
                        {
                           CloseAllOrders(770);
                        }
                  }
            }
      }   
//----
   return(0);
  }
//+------------------------------------------------------------------+
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1025 (permalink)  
Old 03-31-2008, 10:57 PM
Senior Member
 
Join Date: Feb 2006
Posts: 559
Michel is on a distinguished road
Quote:
Originally Posted by ableze_joepardy View Post
owh thank you michel..

btw.. got another question.. ive also modified the mt4 default script to check if any trades opened using script above reach +10 pips.. If got any then close all 5 orders..

example..

Trade 1 lost
Trade 2 lost
Trade 3 +10 pips
Trade 4 Pending
Trade 5 Pending

then close all trades n delete all pending orders with magic no. 770..

can u please check whether the script below will do the job as planne?

Code:
//+------------------------------------------------------------------+
//|                                         AutoClose Same Magic.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

int cnt;
double CurrentProfit;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+

void CloseAllOrders(double MN) {
   bool   result;
   double price;
   int    cmd,error;
  
   while (OrdersTotal() > 0) {
      // Loop through all orders and close them
      for (int i = (OrdersTotal() - 1); i >= 0; i--) {
         if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) {
            if (OrderMagicNumber() == MN) {
               cmd = OrderType();
               if (cmd == OP_BUY) {
               OrderClose(OrderTicket(),OrderLots(),Bid,3,CLR_NONE);
               }
               else if (cmd != OP_BUY && cmd != OP_SELL) {
               OrderDelete(OrderTicket());
               }
            }
         }
      }
   }
}

int start()
  {
//----

for(cnt=OrdersTotal();cnt>=0;cnt--)
      {
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if( OrderMagicNumber()==770 )
            {
               if(OrderType()==OP_BUY)
                  {
                     CurrentProfit=Bid-OrderOpenPrice() ;
                     if(CurrentProfit>10*Point)
                        {
                           CloseAllOrders(770);
                        }
                  }
            }
      }   
//----
   return(0);
  }
//+------------------------------------------------------------------+
It seems it should work, just try it... But the programation is bad: if you have a trade with another MN, or a manual trade, you will enter in an endless loop (the while loop will never stop because you close only the orders fitting with a particular MN).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1026 (permalink)  
Old 04-01-2008, 02:30 AM
Senior Member
 
Join Date: Oct 2007
Posts: 224
Dave137 is on a distinguished road
Question

Realized I had the answer already!

Last edited by Dave137; 04-01-2008 at 04:39 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1027 (permalink)  
Old 04-01-2008, 02:58 AM
Member
 
Join Date: Nov 2006
Posts: 33
winias is on a distinguished road
EA building for dummies

I just noticed this thread after I posted a new one....I think this would be a snap for some of you guys.....

EA building 101 question Need Help please!

I searched for an answer in advance but couldnt come up with much. Any ideas?

Thank you!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1028 (permalink)  
Old 04-01-2008, 03:30 AM
ajk's Avatar
ajk ajk is offline
Senior Member
 
Join Date: Dec 2005
Posts: 232
ajk is on a distinguished road
I want to code to hold a trade for 3 hours but the server time rolls over
from 23:00 to a new time.
How do I exit in 3 hours? ANy suggestions?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1029 (permalink)  
Old 04-03-2008, 10:45 PM
Senior Member
 
Join Date: Oct 2007
Posts: 224
Dave137 is on a distinguished road
Smile Finding RSI High and Low Bars

RSI = 5;

How do I find the number of the most recent bar back of the RSI that has the highest RSI and is also above 75, likewise the most number of the recent bar back of RSI that has the lowest RSI which is also below RSI of 25?

This has me puzzled! Can you help with the statement to solve this??

Much appreciation in advance for your time and effort
!

Dave
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1030 (permalink)  
Old 04-03-2008, 11:19 PM
Linuxser's Avatar
Moderator
 
Join Date: May 2006
Location: Helliconia (Spring)
Posts: 3,322
Blog Entries: 46
Linuxser has disabled reputation
Quote:
Originally Posted by Dave137 View Post
RSI = 5;

How do I find the number of the most recent bar back of the RSI that has the highest RSI and is also above 75, likewise the most number of the recent bar back of RSI that has the lowest RSI which is also below RSI of 25?

This has me puzzled! Can you help with the statement to solve this??

Much appreciation in advance for your time and effort
!

Dave
Maybe:
Code:
         Lowest_RSI=MathMin(Lowest_RSI,iRSI(NULL,0,Periods,MODE,i));
         Highest_RSI=MathMax(Highest_RSI,iRSI(NULL,0,Periods,MODE,i));
__________________
Elite Manual Trading | Portfolio | Calendar | Suggestions to improve the forum | My Blog

Remember: Signatures must have three lines as maximum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
histogram, forex, ZUP_v1.mq4

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

LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/questions/270-ask.html
Posted By For Type Date
OzFx System:) - Page 639 This thread Refback 06-21-2008 10:53 PM
Forex SRDC Sidus Sibkis EA MT4 Forum OTCSmart This thread Refback 12-08-2007 12:46 PM


All times are GMT. The time now is 06:17 AM.



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