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
  #161 (permalink)  
Old 07-02-2006, 03:03 AM
Ruf Ruf is offline
Junior Member
 
Join Date: Jun 2006
Location: Canada
Posts: 8
Ruf is on a distinguished road
Newbie.

I know some c++ but I am struggling with some very basic code.

What I want:

The price is 1.2788. If it moves up to 10 pips I want to buy. If it moves down 10 pips I want to sell.

Do I have the right code?

OrderSend(Symbol(),OP_BUYSTOP,1,Ask+10*Point,slipp age,
(Ask+10*Point)-10*Point,
( Ask+10*Point)+200*Point,”My order comment”,0,0,Green);


OrderSend(Symbol(),OP_SELLSTOP,1,Bid-10*Point,slippage,
(Bid-10*Point)+10*Point,
(Bid -10*Point)-200*Point,”My order comment”,0,0,Green);


I have been reading http://www.metatrader.info/node/34 but im lost. Thanks for your patience.

Last edited by Ruf; 07-02-2006 at 03:13 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #162 (permalink)  
Old 07-04-2006, 03:53 PM
Banned
 
Join Date: Oct 2005
Posts: 387
Bongo is an unknown quantity at this point
Hi,
My problem: MT3,
It is not working. Why?
Thanks, Bongo


sell=false;
buy=false;

if ((C[1]>O[1])<O[0]) then { buy=true; sell=false; }
if ((C[1]<O[1])>O[0]) then { sell=true; buy=false; }
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #163 (permalink)  
Old 07-08-2006, 09:19 PM
Eaglehawk's Avatar
Senior Member
 
Join Date: Jun 2006
Posts: 141
Eaglehawk is on a distinguished road
Post Hey, coders!

Aaragorn and I have been working on this ea lately
PHP Code:
extern int MagicNumber 0;
extern bool SignalMail False;
extern bool EachTickMode False;
extern double Lots 0.1;
extern int Slippage 3;
extern bool StopLossMode False;
extern int StopLoss 5;
extern bool TakeProfitMode True;
extern int TakeProfit 50;
extern bool TrailingStopMode False;
extern int TrailingStop 5;
extern int MaxOpenTrade 1;
extern int Shift 2;
extern double Slope 2;
extern int EnterEMA 38;
extern int ExitEMA 1500;
#define SIGNAL_NONE 0
#define SIGNAL_BUY   1
#define SIGNAL_SELL  2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4

int BarCount;
int Current;
bool TickCheck False;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init() {
   
BarCount Bars;

   if (
EachTickModeCurrent 0; else Current 1;

   return(
0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit() {
   return(
0);
}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start() {
   
int Order SIGNAL_NONE;
   
int TotalTicket;
   
double StopLossLevelTakeProfitLevel;



   if (
EachTickMode && Bars != BarCountTickCheck False;
   
Total OrdersTotal();
   
Order SIGNAL_NONE;

   
//+------------------------------------------------------------------+
   //| Variable Begin                                                   |
   //+------------------------------------------------------------------+

      
double Buy1_1 iMA(NULL0EnterEMA0MODE_EMAPRICE_CLOSECurrent 0);
      
double Buy1_2 iClose(NULL0Current 0);
      
double Buy2_1 iMA(NULL0EnterEMA0MODE_EMAPRICE_CLOSECurrent Shift);
      
double Buy2_2 iClose(NULL0Current Shift);
      
double Sell1_1 iMA(NULL0EnterEMA0MODE_EMAPRICE_CLOSECurrent 0);
      
double Sell1_2 iClose(NULL0Current 0);
      
double Sell2_1 iMA(NULL0EnterEMA0MODE_EMAPRICE_CLOSECurrent Shift);
      
double Sell2_2 iClose(NULL0Current Shift);
      
double CloseBuy1_1 iClose(NULL0Current 0);
      
double CloseBuy1_2 iMA(NULL0ExitEMA0MODE_EMAPRICE_CLOSECurrent 0);
      
double CloseSell1_1 iClose(NULL0Current 0);
      
double CloseSell1_2 iMA(NULL0ExitEMA0MODE_EMAPRICE_CLOSECurrent 0);

   
//+------------------------------------------------------------------+
   //| Variable End                                                     |
   //+------------------------------------------------------------------+

   
bool IsTrade False;

   for (
int i 0Total++) {
      
OrderSelect(iSELECT_BY_POSMODE_TRADES);
      if(
OrderType() <= OP_SELL &&  OrderSymbol() == Symbol()) {
         
IsTrade True
         if(
OrderType() == OP_BUY) {
          
            
//+------------------------------------------------------------------+
            //| Signal Begin(Exit Buy)                                           |
            //+------------------------------------------------------------------+
             
if (Sell1_1 CloseBuy1_2Order SIGNAL_CLOSEBUY;
               
            
//+------------------------------------------------------------------+
            //| Signal End(Exit Buy)                                             |
            //+------------------------------------------------------------------+

            
if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               
OrderClose(OrderTicket(), OrderLots(), BidSlippageMediumSeaGreen);
               if (
SignalMailSendMail("[Signal Alert]""[" Symbol() + "] " DoubleToStr(BidDigits) + " Close Buy");
               if (!
EachTickModeBarCount Bars;
               
IsTrade False;
               continue;
            }
            if(
TrailingStopMode && TrailingStop 0) {                 
               if(
Bid OrderOpenPrice() > Point TrailingStop) {
                  if(
OrderStopLoss() < Bid Point TrailingStop) {
                     
OrderModify(OrderTicket(), OrderOpenPrice(), Bid Point TrailingStopOrderTakeProfit(), 0MediumSeaGreen);
                     if (!
EachTickModeBarCount Bars;
                     continue;
                  }
               }
            }
         } else {

            
//+------------------------------------------------------------------+
            //| Signal Begin(Exit Sell)                                          |
            //+------------------------------------------------------------------+
             
if (Sell1_1 CloseBuy1_2Order SIGNAL_CLOSESELL;
            
//+------------------------------------------------------------------+
            //| Signal End(Exit Sell)                                            |
            //+------------------------------------------------------------------+

            
if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               
OrderClose(OrderTicket(), OrderLots(), AskSlippageDarkOrange);
               if (
SignalMailSendMail("[Signal Alert]""[" Symbol() + "] " DoubleToStr(AskDigits) + " Close Sell");
               if (!
EachTickModeBarCount Bars;
               
IsTrade False;
               continue;
            }
            if(
TrailingStopMode && TrailingStop 0) {                 
               if((
OrderOpenPrice() - Ask) > (Point TrailingStop)) {
                  if((
OrderStopLoss() > (Ask Point TrailingStop)) || (OrderStopLoss() == 0)) {
                     
OrderModify(OrderTicket(), OrderOpenPrice(), Ask Point TrailingStopOrderTakeProfit(), 0DarkOrange);
                     if (!
EachTickModeBarCount Bars;
                     continue;
                  }
               }
            }
         }
      }
   }

   
//+------------------------------------------------------------------+
   //| Signal Begin(Entry logics)                                       |
   //+------------------------------------------------------------------+
      
if (Buy1_1 Buy1_2 && Buy2_1 Buy2_2/* && Buy1_1 + Slope*Point > Buy2_1*/Order SIGNAL_BUY;
      if (
Sell1_1 Sell1_2 && Sell2_1 Sell2_2/* && Sell1_1 + Slope*Point < Sell2_1*/Order SIGNAL_SELL;
   
//+------------------------------------------------------------------+
   //| Signal End                                                       |
   //+------------------------------------------------------------------+

   
if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
      
IsTrade False;//---allows multiple orders to open
      
if(!IsTrade) {
         if (
AccountFreeMargin() < (1000 Lots)) {
            Print(
"We have no money. Free Margin = "AccountFreeMargin());
            return(
0);
         }

         if (
StopLossModeStopLossLevel Ask StopLoss Point; else StopLossLevel 0.0;
         if (
TakeProfitModeTakeProfitLevel Ask TakeProfit Point; else TakeProfitLevel 0.0;
         if(
OrdersTotal() < MaxOpenTrade)
         
Ticket OrderSend(Symbol(), OP_BUYLotsAskSlippageStopLossLevelTakeProfitLevel"Buy(#" MagicNumber ")"MagicNumber0DodgerBlue);
         if(
Ticket 0) {
            if (
OrderSelect(TicketSELECT_BY_TICKETMODE_TRADES)) {
                Print(
"BUY order opened : "OrderOpenPrice());
                if (
SignalMailSendMail("[Signal Alert]""[" Symbol() + "] " DoubleToStr(AskDigits) + " Open Buy");
            } else {
                Print(
"Error opening BUY order : "GetLastError());
            }
         }
         if (
EachTickModeTickCheck True;
         if (!
EachTickModeBarCount Bars;
         return(
0);
      }
   }


   if (
Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
      
IsTrade False;//---allows multiple orders to open
      
if(!IsTrade) {
         if (
AccountFreeMargin() < (1000 Lots)) {
            Print(
"We have no money. Free Margin = "AccountFreeMargin());
            return(
0);
         }

         if (
StopLossModeStopLossLevel Bid StopLoss Point; else StopLossLevel 0.0;
         if (
TakeProfitModeTakeProfitLevel Bid TakeProfit Point; else TakeProfitLevel 0.0;
         if(
OrdersTotal() < MaxOpenTrade)
         
Ticket OrderSend(Symbol(), OP_SELLLotsBidSlippageStopLossLevelTakeProfitLevel"Sell(#" MagicNumber ")"MagicNumber0DeepPink);
         if(
Ticket 0) {
            if (
OrderSelect(TicketSELECT_BY_TICKETMODE_TRADES)) {
                Print(
"SELL order opened : "OrderOpenPrice());
                if (
SignalMailSendMail("[Signal Alert]""[" Symbol() + "] " DoubleToStr(BidDigits) + " Open Sell");
            } else {
                Print(
"Error opening SELL order : "GetLastError());
            }
         }
         if (
EachTickModeTickCheck True;
         if (!
EachTickModeBarCount Bars;
         return(
0);
      }
   }

   if (!
EachTickModeBarCount Bars;

   return(
0);
}
//+------------------------------------------------------------------+ 
"Shift" is how many periods you look back, and "Slope" is how many pips the "EnterEMA" has moved up in the "Shift". We're still perfecting the strategy, and I was wondering if you could help me with something.
__________________
"One's ability to accomplish his or her goals is limited only by the ingenuity of how one uses what he or she already knows."- Eaglehawk
REMEMBER,
"Genius is nothing but a greater aptitude for patience." –Benjamin Franklin

____________________________________

Have a simple ea you just can't figure out how to code??? Odds are you can make it here. Just remember to push complete when you're done, NOT SAVE!!!

http://sufx.core.t3-ism.net/ExpertAdvisorBuilder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #164 (permalink)  
Old 07-08-2006, 09:19 PM
Eaglehawk's Avatar
Senior Member
 
Join Date: Jun 2006
Posts: 141
Eaglehawk is on a distinguished road
Arrow the channel detector

i have attatched a chart of where it has taken trades, and also another one for a picture example of what i'm looking for, (to help keep you on the know of what i'm talking about)

notice at the beggining of the chart, it stays flat forever, i want to stay out of trades when the prices channels horizontally, for x pips, with a high and low of x pips, and after it breaches that channel by x pips, re-activate.

If (a) trade(s) are open when a channel is reached by all the above conditions, to close the trade(s)

I'll appriciate all assistance i recieve on the matter!
__________________
"One's ability to accomplish his or her goals is limited only by the ingenuity of how one uses what he or she already knows."- Eaglehawk
REMEMBER,
"Genius is nothing but a greater aptitude for patience." –Benjamin Franklin

____________________________________

Have a simple ea you just can't figure out how to code??? Odds are you can make it here. Just remember to push complete when you're done, NOT SAVE!!!

http://sufx.core.t3-ism.net/ExpertAdvisorBuilder

Last edited by Eaglehawk; 10-21-2006 at 06:37 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #165 (permalink)  
Old 07-08-2006, 11:39 PM
Aaragorn's Avatar
Senior Member
 
Join Date: Jun 2006
Location: USA
Posts: 801
Aaragorn is on a distinguished road
this is to give some context before I narrow down to the code I have a question about...

PHP Code:
#property copyright "Aaragorn"
#property link      "http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/"

extern int MagicNumber 0;
extern bool SignalMail False;
extern bool EachTickMode False;
extern double Lots 0.35;
extern int Slippage 3;
extern bool StopLossMode False;
extern int StopLoss 5;

extern bool TakeProfitMode True;
extern int TakeProfit 42;
extern bool TrailingStopMode False;
extern int TrailingStop 10;
extern int MaxOpenTrade 1;
extern int Shift 3;
//extern double Slope = 2;
extern int EntLongEMA 46;
extern int EntShortEMA 1;
extern int ExitEMA 52;
extern int TrendEMA 150;
//+-----------close based on not triggering trailing stop in allotted time----------------+
extern int  MonitorInMinutes 60;  // minutes after open to check state of trade
extern int  ThresholdMove    1;   // if after that time we don't have +'x' pips we will exit
extern int  MinsMultiplier   90;   // multiplies the MonitorInMinutes to make minutes (if 'x'=60) into hours
#define SIGNAL_NONE 0
#define SIGNAL_BUY   1
#define SIGNAL_SELL  2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4

int BarCount;
int Current;
bool TickCheck False;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init() {
   
BarCount Bars;

   if (
EachTickModeCurrent 0; else Current 1;

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

   
int Order SIGNAL_NONE;
   
int TotalTicket;
   
double StopLossLevelTakeProfitLevel;



   if (
EachTickMode && Bars != BarCountTickCheck False;
   
Total OrdersTotal();
   
Order SIGNAL_NONE;

   
//+------------------------------------------------------------------+
   //| Variable Begin                                                   |
   //+------------------------------------------------------------------+

      
double Buy1_1 iMA(NULL0EntLongEMA0MODE_EMAPRICE_CLOSECurrent 0);
      
double Buy1_2 iMA(NULL0EntShortEMA0MODE_EMAPRICE_CLOSECurrent 0);
      
double Buy2_1 iMA(NULL0EntLongEMA0MODE_EMAPRICE_CLOSECurrent Shift);
      
double Buy2_2 iMA(NULL0EntShortEMA0MODE_EMAPRICE_CLOSECurrent Shift);
      
double Sell1_1 iMA(NULL0EntLongEMA0MODE_EMAPRICE_CLOSECurrent 0);
      
double Sell1_2 iMA(NULL0EntShortEMA0MODE_EMAPRICE_CLOSECurrent 0);
      
double Sell2_1 iMA(NULL0EntLongEMA0MODE_EMAPRICE_CLOSECurrent Shift);
      
double Sell2_2 iMA(NULL0EntShortEMA0MODE_EMAPRICE_CLOSECurrent Shift);
      
double CloseBuy1_1 iMA(NULL0EntShortEMA0MODE_EMAPRICE_CLOSECurrent 0);
      
double CloseBuy1_2 iMA(NULL0ExitEMA0MODE_EMAPRICE_CLOSECurrent 0);
      
double CloseSell1_1 iMA(NULL0EntShortEMA0MODE_EMAPRICE_CLOSECurrent 0);
      
double CloseSell1_2 iMA(NULL0ExitEMA0MODE_EMAPRICE_CLOSECurrent 0);
      
double C_trendsetter iMA(NULL0TrendEMA0MODE_EMAPRICE_CLOSECurrent 0);
      
double S_trendsetter iMA(NULL0TrendEMA0MODE_EMAPRICE_CLOSECurrent Shift);
      
   
//+------------------------------------------------------------------+
   //| Variable End                                                     |
   //+------------------------------------------------------------------+

   //Check position
   
bool IsTrade False;

   for (
int i 0Total++) {
      
OrderSelect(iSELECT_BY_POSMODE_TRADES);
      if(
OrderType() <= OP_SELL &&  OrderSymbol() == Symbol()) {
         
IsTrade True
      &nb