• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 11:34pm
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 11:34pm
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

Basic Alt Key/Entry Script - Simplest Script Ever 1 reply

Wrong Candle Open Time: IBFX 0 replies

EA needs code adjusted to IBFX new policy 17 replies

i like to add an indicator script into my own script. what would be the best idea? 3 replies

ibfx live script to close all positions 6 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe

What's wrong with this IBFX script code?

  • Post #1
  • Quote
  • First Post: Jan 27, 2009 11:48am Jan 27, 2009 11:48am
  •  permanentjaun
  • | Joined Oct 2006 | Status: Member | 655 Posts
I downloaded and installed the quick scripts from the IBFX website. They work fine in their default settings. The problem is they don't work when I alter them to enter trades with a specific lot size per trade rather than the script determining lot sizing based on percentage of margin.

Here is the complete code:


//+-------------------------------------------------------------------------+
//| IBFX - Quick Sell.mq4 |
//+-------------------------------------------------------------------------+
#property copyright "Copyright 2008, ibfx.com"
#property link "www.ibfx.com"
//----
int start()
{
/*+-------------------------------------------------------------------+
Because these scripts are meant to execute fast there are no user
external inputs. Make sure to modify the settings below, then compile
the script before assigning a hot key to it and using it.
The magicNumber HAS TO TO BE THE SAME ON ALL SCRIPTS if you change it
here make sure to change it on all scripts!!!
Do not forget to click on COMPILE once your changes have been made!!!
+-------------------------------------------------------------------+*/
int MagicNumber = 915;
double Risk = 1.0;
int StopLoss = 20; // Number in Pips ie: 50 for 50 pips.
int ProfitTarget = 0; // Number in Pips ie: 50 for 50 pips.
int Slippage = 1;
bool MiniLots = True; // Does your broker offer mini micro lots such as 0.01 lot?
string Commentary = " IBFX - Quick Sell ";
string FontName = "Arial";
int FontSize = 12;

//+-------------------------------------------------------------------------+
//| DO NOT MODIFY ANYTHING BELOW THIS LINE!!! |
//+-------------------------------------------------------------------------+
//---- A few checks before we get started
if( !IsConnected() ) { Alert( Commentary + " - No Connection!!" ); return(0); }

//---- Specific Vars
int Action = OP_SELL;
double InitPrice = Bid;

//---- Global Vars
bool Done = False;
string Symbole = Symbol();
int Ticket = 0;
int ErrorCode = 0;
double MaxLots = MarketInfo( Symbole, MODE_MAXLOT );
double Lots = MM( Symbole, Risk, MiniLots );
Comment( "IBFX - QuickSell | Placing Short Order, please wait ..." );
//---- Let's place the order.
while( !Done )
{
double FillPrice = Bid;
double StopPrice = Ask;

if( MathAbs( InitPrice - FillPrice ) > Slippage * Point ) { Done = true; }
Wait();
Ticket = OrderSend( Symbole, Action, Lots, FillPrice, Slippage * Point, StopShort( StopPrice, StopLoss ), TakeShort(FillPrice, ProfitTarget), Commentary, MagicNumber, 0, CLR_NONE );
if( Ticket >= 0 ) { Done = true; }
else
{
ErrorCode = GetLastError();
if( ErrorCode == 4109 ) { Alert( Commentary + " - You did not allow live trading!" ); Done = true; }
else if( ErrorCode == 134 ) { Alert( Commentary + " - Not enough Money!" ); Done = true; }
else if( ErrorCode == 138 || ErrorCode == 136 || ErrorCode == 135 ) { Alert( Commentary + " - Requote/Slippage, run the script again" ); Done = true; }
else { Alert( Commentary + " Error: " + ErrorCode ); }
}
}
Comment("");

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

//+-------------------------------------------------------------------------+
//+ Wait +
//+-------------------------------------------------------------------------+
void Wait() { while( IsTradeContextBusy() ) { Sleep(50); } }
//+-------------------------------------------------------------------------+
//+-------------------------------------------------------------------------+
//| Calculate Stop Short |
//+-------------------------------------------------------------------------+
double StopShort(double price,int stop)
{
if(stop==0) { return(0); }
else { return(price+(stop*Point)); }
}
//+-------------------------------------------------------------------------+
//| Calculate Profit Target Short |
//+-------------------------------------------------------------------------+
double TakeShort(double price,int take)
{
if(take==0) { return(0);}
else { return(price-(take*Point));}
}
//+-------------------------------------------------------------------------+
//+-------------------------------------------------------------------------+
//| Money Managment |
//+-------------------------------------------------------------------------+
double MM( string Sym, double Risk, bool BrokerAllowsFractionalLots )
{
double MinLots = MarketInfo(Sym,MODE_MINLOT);
double MaxLots = MarketInfo(Sym,MODE_MAXLOT);
double Leverage = AccountLeverage();
double LotSize = MarketInfo(Sym,MODE_LOTSIZE);
double LotStep = MarketInfo(Sym,MODE_LOTSTEP);

double FinalAccountBalance = MathMin( AccountBalance(), AccountEquity() );
int NormalizationFactor = 0;
double Lots = 0.0;

if(LotStep == 0.01) { NormalizationFactor = 2; }
if(LotStep == 0.1) { NormalizationFactor = 1; }

if( BrokerAllowsFractionalLots == true)
{
Lots = (FinalAccountBalance*(Risk/100.0))/(LotSize/Leverage);
Lots = StrToDouble(DoubleToStr(Lots, NormalizationFactor));
if (Lots < MinLots) { Lots = MinLots; }
if (Lots > MaxLots) { Lots = MaxLots; }
}
else if(BrokerAllowsFractionalLots == false)
{
Lots = (FinalAccountBalance*(Risk/100.0))/(LotSize/Leverage);
Lots = MathRound(Lots);
if (Lots < MinLots) { Lots = MinLots; }
if (Lots > MaxLots) { Lots = MaxLots; }
}
return( Lots );
}


The part in bold is where the IBFX video says to adjust if I want to adjust it to enter specific trades. In its default mode it is:

double Lots = MM( Symbole, Risk, MiniLots );

I want to risk .2 lots per trade so I change the code to:

double Lots = .20; //MM( Symbole, Risk, MiniLots );


This gives me an error when I compile that says, "Function MM is not referenced and will be removed from the exp-file."

I tried running the script anyways on a demo account and it kept giving me an 'error 2' message. Eventually it froze my platform.

How do I fix this? I followed the instructions on IBFX's website at http://www.ibfx.com/tools/quickscripts/default.aspx

Please help.

Thanks,
Matt
  • Post #2
  • Quote
  • Jan 27, 2009 12:00pm Jan 27, 2009 12:00pm
  •  LongToBeFree
  • | Membership Revoked | Joined Oct 2008 | 613 Posts
1 - you are not getting an error message on compile. That is simply an informational and that makes sense since you're replacing the call to the MM function

2 - I dont know what error 2 is but I'm guessing it has to do with the magic number. Read the comments in the code, it clearly asks for magic number 915. Do your trades have this? This would mostly only apply for trades that you've opened with an EA. If you're using this script on a manually-opened trade, you wouldn't have anything to apply this scrip to

Go check this - after you do some more math lessons
 
 
  • Post #3
  • Quote
  • Jan 27, 2009 12:03pm Jan 27, 2009 12:03pm
  •  permanentjaun
  • | Joined Oct 2006 | Status: Member | 655 Posts
Quoting LongToBeFree
Disliked
1 - you are not getting an error message on compile. That is simply an informational and that makes sense since you're replacing the call to the MM function

2 - I dont know what error 2 is but I'm guessing it has to do with the magic number. Read the comments in the code, it clearly asks for magic number 915. Do your trades have this? This would mostly only apply for trades that you've opened with an EA. If you're using this script on a manually-opened trade, you wouldn't have anything to apply this scrip to

Go check this - after you do some more...
Ignored
I am running this for manual trade execution so the magic number shouldn't matter. The error 2 message only occurs when I adjust the lot size function.

My math is fine.
 
 
  • Post #4
  • Quote
  • Jan 27, 2009 12:06pm Jan 27, 2009 12:06pm
  •  LongToBeFree
  • | Membership Revoked | Joined Oct 2008 | 613 Posts
Quoting permanentjaun
Disliked
I am running this for manual trade execution so the magic number shouldn't matter. The error 2 message only occurs when I adjust the lot size function.

My math is fine.
Ignored
Highly doubtful
 
 
  • Post #5
  • Quote
  • Jan 27, 2009 12:07pm Jan 27, 2009 12:07pm
  •  permanentjaun
  • | Joined Oct 2006 | Status: Member | 655 Posts
For some reason the script works now. I don't know why. Perhaps because I had initially changed the lot size code to 0.20 instead of just .20?
 
 
  • Post #6
  • Quote
  • Jan 27, 2009 12:11pm Jan 27, 2009 12:11pm
  •  LongToBeFree
  • | Membership Revoked | Joined Oct 2008 | 613 Posts
Quoting permanentjaun
Disliked
For some reason the script works now. I don't know why. Perhaps because I had initially changed the lot size code to 0.20 instead of just .20?
Ignored
The leading zero shouldn't error out like that, but stranger things have happened with MQL.
 
 
  • Post #7
  • Quote
  • Last Post: Jan 28, 2009 7:51pm Jan 28, 2009 7:51pm
  •  Dale
  • | Joined Feb 2008 | Status: Member | 573 Posts
The leading Zero or not will cause it to error in some cases, do not know why.


Dale
 
 
  • Platform Tech
  • /
  • What's wrong with this IBFX script code?
  • Reply to Thread
0 traders viewing now
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2022