Go Back   Forex-TSD > Programming > MetaTrader Programming
Forex Forum Register More recent Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #2071 (permalink)  
Old 09-27-2009, 10:44 PM
Senior Member
 
Join Date: Oct 2008
Location: Vancouver, BC
Posts: 166
Roger09 is on a distinguished road
Quote:
Originally Posted by fxbg View Post
Hi,
Could someone please let me know how I can place a fixed StopLoss in ths code?
Replace
Code:
extern double Lots       = 0.1; 
extern int ChannelPeriod = 25; 
extern int Slippage      = 3; 
extern int TakeProfit    = 15; 
//+------------------------------------------------------------------+ 
double LastOrderTime = 0; 
double CurrentDirection = 0; 
double CurrentTakeProfitPrice = 0; 
//+------------------------------------------------------------------+ 
void OpenLong() 
{ 
   if (Time[0] == LastOrderTime) 
      return; 
   if (CurrentDirection != 0) 
      return; 

   OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, 
             "Daydream", MAGIC_NUM, 0, Blue); 
   LastOrderTime = Time[0]; 
   CurrentDirection = 1; 
} 
//+------------------------------------------------------------------+ 
void OpenShort() 
{ 
   if (Time[0] == LastOrderTime) 
      return; 
   if (CurrentDirection != 0) 
      return; 

   OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, 
             "Daydream", MAGIC_NUM, 0, Red); 
   LastOrderTime = Time[0]; 
   CurrentDirection = -1; 
}
to
Code:
extern double Lots       = 0.1; 
extern int ChannelPeriod = 25; 
extern int Slippage      = 3; 
extern int TakeProfit    = 15; 
extern int StopLoss     = 15;
//+------------------------------------------------------------------+ 
double LastOrderTime = 0; 
double CurrentDirection = 0; 
double CurrentTakeProfitPrice = 0; 
//+------------------------------------------------------------------+ 
void OpenLong() 
{ 
   if (Time[0] == LastOrderTime) 
      return; 
   if (CurrentDirection != 0) 
      return; 

   OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, Ask-StopLoss*Point, 0, 
             "Daydream", MAGIC_NUM, 0, Blue); 
   LastOrderTime = Time[0]; 
   CurrentDirection = 1; 
} 
//+------------------------------------------------------------------+ 
void OpenShort() 
{ 
   if (Time[0] == LastOrderTime) 
      return; 
   if (CurrentDirection != 0) 
      return; 

   OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, Bid+StopLoss*Point, 0, 
             "Daydream", MAGIC_NUM, 0, Red); 
   LastOrderTime = Time[0]; 
   CurrentDirection = -1; 
}
__________________
www.rogersignals.com - Web-copying and monitoring
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
  #2072 (permalink)  
Old 09-27-2009, 11:20 PM
Member
 
Join Date: Sep 2006
Posts: 97
asam is on a distinguished road
Need help modify the indicator

Hi all programmer,

I found an indicator (currency positions) in the forum which shows the current positions I am trading. Now I want to find someone out there help me make this indicator to use external window at the bottom of the chart, also the fonts and color can be changed. I am not good at program. Thanks a lot.

asam
Attached Files
File Type: mq4 CurrencyPositions.mq4 (4.5 KB, 9 views)
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
  #2073 (permalink)  
Old 09-28-2009, 09:13 AM
Junior Member
 
Join Date: Nov 2006
Posts: 2
fxbg is on a distinguished road
Don't work in tester

I start this EA in tester .When it reach the first Stoploss tester stop and don't continue make a test.Is it possible to correct this problem.Thank you Roger.

PHP Code:
//+------------------------------------------------------------------+
//|                                              Daydream by Cothool |
//|                                          Recommended: USD/JPY 1H |
//+------------------------------------------------------------------+
#define MAGIC_NUM  48213657
//+------------------------------------------------------------------+
extern double Lots       0.1;
extern int ChannelPeriod 25;
extern int Slippage      3;
extern int TakeProfit    0;
extern int StopLoss     15;
//+------------------------------------------------------------------+
double LastOrderTime 0;
double CurrentDirection 0;
double CurrentTakeProfitPrice 0;
//+------------------------------------------------------------------+
void OpenLong()
{
   if (
Time[0] == LastOrderTime)
      return;
   if (
CurrentDirection != 0)
      return;

   
OrderSend(Symbol(), OP_BUYLotsAskSlippage,Ask-StopLoss*Point0,
             
"Daydream"MAGIC_NUM0Blue);
   
LastOrderTime Time[0];
   
CurrentDirection 1;
}
//+------------------------------------------------------------------+
void OpenShort()
{
   if (
Time[0] == LastOrderTime)
      return;
   if (
CurrentDirection != 0)
      return;

   
OrderSend(Symbol(), OP_SELLLotsBidSlippage,Bid+StopLoss*Point0,
             
"Daydream"MAGIC_NUM0Red);
   
LastOrderTime Time[0];
   
CurrentDirection = -1;
}
//+------------------------------------------------------------------+
void CloseLong()
{
   
int i;

   if (
Time[0] == LastOrderTime)
      return;
   if (
CurrentDirection != 1)
      return;

   for (
0OrdersTotal(); i++)
   {
      if (
OrderSelect(iSELECT_BY_POS) && OrderSymbol() == Symbol() &&
          
OrderMagicNumber() == MAGIC_NUM && OrderType() == OP_BUY)
      {
         
OrderClose(OrderTicket(), OrderLots(), Bid3White);
         
LastOrderTime Time[0];
         
CurrentDirection 0;
      }
   }
}
//+------------------------------------------------------------------+
void CloseShort()
{
   
int i;

   if (
Time[0] == LastOrderTime)
      return;
   if (
CurrentDirection != -1)
      return;

   for (
0OrdersTotal(); i++)
   {
      if (
OrderSelect(iSELECT_BY_POS) && OrderSymbol() == Symbol() &&
          
OrderMagicNumber() == MAGIC_NUM && OrderType() == OP_SELL)
      {
         
OrderClose(OrderTicket(), OrderLots(), Ask3White);
         
LastOrderTime Time[0];
         
CurrentDirection 0;
      }
   }
}
//+------------------------------------------------------------------+
void start()
{
   
double HighestValue;
   
double LowestValue;

   
HighestValue High[Highest(NULL0MODE_HIGHChannelPeriod1)];
   
LowestValue Low[Lowest(NULL0MODE_LOWChannelPeriod1)];

   
// BUY
   
if (Close[0] < LowestValue)
   {
      
CloseShort();
      
OpenLong();
      
CurrentTakeProfitPrice Bid TakeProfit Point;
   }

   
// SELL
   
if (Close[0] > HighestValue)
   {
      
CloseLong();
      
OpenShort();
      
CurrentTakeProfitPrice Ask TakeProfit Point;
   }

   
// Trailing Profit Taking for Long Position
   
if (CurrentDirection == 1)
   {
      if (
CurrentTakeProfitPrice Bid TakeProfit Point)
         
CurrentTakeProfitPrice Bid TakeProfit Point;
      if (
Bid >= CurrentTakeProfitPrice)
         
CloseLong();
   }

   
// Trailing Profit Taking for Short Position
   
if (CurrentDirection == -1)
   {
      if (
CurrentTakeProfitPrice Ask TakeProfit Point)
         
CurrentTakeProfitPrice Ask TakeProfit Point;
      if (
Ask <= CurrentTakeProfitPrice)
         
CloseShort();
   }
}
//+------------------------------------------------------------------+ 
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
  #2074 (permalink)  
Old 09-28-2009, 04:05 PM
Senior Member
 
Join Date: Jan 2006
Posts: 404
nicesurf is on a distinguished road
The code is amazing, 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
  #2075 (permalink)  
Old 09-28-2009, 04:48 PM
Senior Member
 
Join Date: Oct 2008
Location: Vancouver, BC
Posts: 166
Roger09 is on a distinguished road
Thumbs down

To fxbg
Adjust your logic. When you close the order by program, you change CurrentDirection to 0, but, if it is closed by stoploss - not.
__________________
www.rogersignals.com - Web-copying and monitoring
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
  #2076 (permalink)  
Old 09-30-2009, 06:14 AM
Junior Member
 
Join Date: Sep 2007
Posts: 6
tradertt is on a distinguished road
Can anyone help me edit this code so that it only checks for this formation on close

Hi GUys,

Can anyone help me edit this indicator that will search for a certain bar formation ONLY say 5 mins before the close of the bar on the timeframe I am on.

Thank you

Code:
//+------------------------------------------------------------------+
//|                                             outside_days_v01.mq4 |
//|                                       Copyright © 2008, Akuma99. |
//|                                    http://www.beginnertrader.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Akuma99."
#property link      "http://www.beginnertrader.com"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red

double upArrows[];
double downArrows[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   //---- indicators
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexBuffer(0,upArrows);
   SetIndexArrow(0,233);

   SetIndexStyle(1,DRAW_ARROW);
   SetIndexBuffer(1,downArrows);
   SetIndexArrow(1,234);
   //----
   return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
void start()
  {
   int    counted_bars=IndicatorCounted();

   if (counted_bars < 0) {
      return(-1);
   } else {
      counted_bars--;
   }

   int    limit = Bars - counted_bars;

   int i;
   for (i=0; i<limit; i++) {
      if (Close[i] >= (Low[i]+0.7*(High[i]-Low[i])) && (Open[i] >= Low[i]+0.7*(High[i]-Low[i])) && (Open[i] >= Low[i+1]) && (Close[i] >= Low[i+1]) && (Open[i] <= High[i+1]) && (High[i] <= High[i+1]) && (Close[i] <= High[i+1]) && (Low[i] <= Low[i+1] - 0.3*(High[i]-Low[i])) && (1*(High[i] - Low[i]) >= ((High[i+1] - Low[i+1]) + (High[i+2] - Low[i+2]) + (High[i+3] - Low[i+3]) + (High[i+4] - Low[i+4]) + (High[i+5] - Low[i+5]))/5)) {
         if (Close[i] >= Low[i+1]) {
            upArrows[i] = Low[i] -0.3*(High[i]-Low[i]);
           // PlaySound("Alert.wav");
            Alert(Symbol(), " Bullish Pin Bar");
         } else if (Close[i] < Low[i+1]) {
            downArrows[i] = High[i];
           // PlaySound("Alert.wav");
            Alert(Symbol(), " Bullish Pin Bar");
         }
      }
   }

  }
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
  #2077 (permalink)  
Old 10-01-2009, 10:27 PM
Member
 
Join Date: Sep 2009
Location: Malta
Posts: 51
ljuba973 is on a distinguished road
Comparing values

Hi all,

Very simple question as I am not sure that I understood properly values of indicators !?

I have values like this:

laADX00 = iADX(NULL,0,14,PRICE_CLOSE,MODE_MAIN,0);
laADXP0 = iADX(NULL,0,14,PRICE_CLOSE,MODE_PLUSDI,0);
laADXM0 = iADX(NULL,0,14,PRICE_CLOSE,MODE_MINUSDI,0);
laADX01 = iADX(NULL,0,14,PRICE_CLOSE,MODE_MAIN,1);
laADXP1 = iADX(NULL,0,14,PRICE_CLOSE,MODE_PLUSDI,1);
laADXM1 = iADX(NULL,0,14,PRICE_CLOSE,MODE_MINUSDI,1);
laADX02 = iADX(NULL,0,14,PRICE_CLOSE,MODE_MAIN,2);
laADXP2 = iADX(NULL,0,14,PRICE_CLOSE,MODE_PLUSDI,2);
laADXM2 = iADX(NULL,0,14,PRICE_CLOSE,MODE_MINUSDI,2);

and if later on I have something like:

Addon= "";
if (laADX02 > laADX01 && laADX01 > laADX00) Addon= "Up laADX0";
if (laADX02 < laADX01 && laADX01 < laADX00) Addon= "Down laADX0";
if (laADX02 > laADX01 && laADX01 < laADX00) Addon= "Top laADX0";
if (laADX02 < laADX01 && laADX01 > laADX00) Addon= "Bottom laADX0";
Print Addon.....
Addon= "";
if (laADXP2 > laADXP1 && laADXP1 > laADXP0) Addon= "Up laADXP";
if (laADXP2 < laADXP1 && laADXP1 < laADXP0) Addon= "Down laADXP";
if (laADXP2 > laADXP1 && laADXP1 < laADXP0) Addon= "Top laADXP";
if (laADXP2 < laADXP1 && laADXP1 > laADXP0) Addon= "Bottom laADXP";
Print Addon.....
Addon= "";
if (laADXM2 > laADXM1 && laADXM1 > laADXM0) Addon= "Up laADXM";
if (laADXM2 < laADXM1 && laADXM1 < laADXM0) Addon= "Down laADXM";
if (laADXM2 > laADXM1 && laADXM1 < laADXM0) Addon= "Top laADXM";
if (laADXM2 < laADXM1 && laADXM1 > laADXM0) Addon= "Bottom laADXM";

And I have printed that for example UP laADXM ...and on chart ADX DI- id going down or something else but not rising. Similar for RSI, CCI, MACD, ...

What is wrong here? I understood that defined like above laADX00 is value of ADX at the moment, laADX01 is value of ADX for previous bar at the moment when price is closed for that bar, laADX02 is value of ADX for 2 bars ago at the moment when price is closed for that bar. Is that correct or laADX01 is ADX value for previous tick and laADX02 for 2 ticks ago?

Can somebody clarify this to me please as charts and these definitions are not 1:1?

PS: I tested my EA in Strategy Simulator when I saw these contradiction results

Thanks in advance

Aleksandar
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
  #2078 (permalink)  
Old 10-01-2009, 10:34 PM
Member
 
Join Date: Sep 2009
Location: Malta
Posts: 51
ljuba973 is on a distinguished road
Sorry ... example was wrong ... this is from my script ... but anyhow simulator present it different than printed sentence

Addon= "";
if (laADX02 < laADX01 && laADX01 < laADX00) Addon= "Up laADX0";
if (laADX02 > laADX01 && laADX01 > laADX00) Addon= "Down laADX0";
if (laADX02 < laADX01 && laADX01 > laADX00) Addon= "Top laADX0";
if (laADX02 > laADX01 && laADX01 < laADX00) Addon= "Bottom laADX0";
Print Addon.....
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
  #2079 (permalink)  
Old 10-03-2009, 11:54 AM
Junior Member
 
Join Date: Jan 2009
Posts: 4
koolrafa is on a distinguished road
need help scripting

Hi!

Need help understanding how to use orderselect().

I'd like to know if it's possible to set a variable with the same value of orderprofit() .
Thank You
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
  #2080 (permalink)  
Old 10-03-2009, 12:44 PM
Junior Member
 
Join Date: Jan 2009
Posts: 4
koolrafa is on a distinguished road
One more thing is there a way to close all open orders???
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
Reply

Bookmarks

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


Currently Active Users Viewing This Thread: 2 (0 members and 2 guests)
 
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 04:22 PM


All times are GMT. The time now is 03:31 AM.



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