# Problem with spread and point

385

Hello everyone,

I am experiencing problems applying variables "points" and "Spread" to a decimal values. What does the value shown in points mean?

How do I get Spread to show only 2 places after the decimal point?

I have attached the values that I received while I was debugging the code.

```void RunTest()
{
points = MarketInfo(Symbol(),MODE_POINT);  // 1e-05.0
}```
48603

GrumpyDuckMan:

Hello everyone,

I am experiencing problems applying variables "points" and "Spread" to a decimal values. What does the value shown in points mean?

How do I get Spread to show only 2 places after the decimal point?

I have attached the values that I received while I was debugging the code.

```//------------ use

Moderator
2322

You can also retrieve it directly without doing a calculation e.g.

New style:

```   long spread = SymbolInfoInteger(_Symbol,SYMBOL_SPREAD);
```

Old style:

```   int spread = MarketInfo(_Symbol,MODE_SPREAD);
```

That is going to give you a figure like 10 or 20.

That means 10 (or 20) points, which is 1 (or 2) pips in common parlance for most brokers.

GrumpyDuckMan:

What does the value shown in points mean? 1e-05.0

It is just another way to write 0.00001

It means move the decimal point 5 places to the left (to the left because it is negative)

1 place left = 0.1

2 places left = 0.01

3 places left = 0.001

4 places left = 0.0001

5 places left = 0.00001

GrumpyDuckMan:

How do I get Spread to show only 2 places after the decimal point?

Quite often you may come across lots of extra zeros and some random digits at the end of a number.

This isn't a bug, it is the way floating point numbers are stored in binary.

Don't get bogged down in the reasons why (unless you really want to), just control the output when you want to display it.

You can use PrintFormat() or StringFormat() to control the display of numbers

Example to print a number to 2 decimal places:

```   double number = 0.6583473459847;
PrintFormat("%.2f",number);```

Result: 0.66

385

Thanks,

You have both been very helpful.

If I right click "Profit" and move to "profit" I have three options "as Points", "as Term Currency" and "as Deposit Currency".

I usually look at "term Currency" and "Points". I am just trying to work out how "As Points" can be adapted in to code.

385

honest_knave:

You can also retrieve it directly without doing a calculation e.g.

New style:

Old style:

That is going to give you a figure like 10 or 20.

That means 10 (or 20) points, which is 1 (or 2) pips in common parlance for most brokers.

It is just another way to write 0.00001

It means move the decimal point 5 places to the left (to the left because it is negative)

1 place left = 0.1

2 places left = 0.01

3 places left = 0.001

4 places left = 0.0001

5 places left = 0.00001

Quite often you may come across lots of extra zeros and some random digits at the end of a number.

This isn't a bug, it is the way floating point numbers are stored in binary.

Don't get bogged down in the reasons why (unless you really want to), just control the output when you want to display it.

You can use PrintFormat() or StringFormat() to control the display of numbers

Example to print a number to 2 decimal places:

Result: 0.66

I'm not sure I totally understand. I will give it at go.
385

GrumpyDuckMan:
I'm not sure I totally understand. I will give it at go.

1e = 30

Is that right?

Moderator
2322

GrumpyDuckMan:
I'm not sure I totally understand. I will give it at go.

Most of it is getting your head around the difference between the values stored in your variables, and how you make them look when you print or otherwise display them.

Using a simple example of an indicator that shows the current spread in the chart comment

```int OnInit()
{
return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason)
{
Comment(""); // clear the chart comment when you remove the indicator
}

int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
{
if(Digits%2==1) sprd/=10;  // convert points to pips
return(rates_total);
}```

Moderator
2322

GrumpyDuckMan:

1e = 30

Is that right?

No, don't get confused between the notation "1e-05.0" and the codes you use in StringFormat() and PrintFormat().

StringFormat() and PrintFormat() are very useful tools, but if you find them confusing you could change the code I posted above like this:

```   double sprd  = (double)SymbolInfoInteger(_Symbol,SYMBOL_SPREAD); // get the spread in points
if(Digits%2==1) sprd/=10;  // convert points to pips
Comment("Spread: ", DoubleToString(sprd,1), " pips"); // display the spread in the chart comment
```

I think I may be unnecessarily confusing you because I'm not entirely sure what you are trying to achieve...

385

Hello,

This is the entire code I have currently, I tried to make it as tidy as possible to read.

```//+------------------------------------------------------------------+
#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
input ENUM_MA_METHOD Method =MODE_SMA;
input float Amount,Amount1;
int SortLoss,SortProfit;
//+------------------------------------------------------------------+
enum symbols {EURUSD,
USDJPY,
GOLD,
AUDUSD,
};
input symbols symbol;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
RunTest();

return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
}
//+------------------------------------------------------------------+
{
string sym = EnumToString(symbol);
// you'll also need to deal with broker suffix / prefix
bid    = SymbolInfoDouble(sym,SYMBOL_BID),
pnt    = SymbolInfoDouble(sym,SYMBOL_POINT);
int    digits = (int)SymbolInfoInteger(sym,SYMBOL_DIGITS);
if(ticket<1)
{
Print("Debug",GetLastError());
}
else
Print("Order successfully");
}
//+------------------------------------------------------------------+
void StartSellOrders()
{
double minstoplevel=MarketInfo(Symbol(),MODE_STOPLEVEL);
double stoploss=0;
double takeprofit=0;
int ticket=OrderSend(Symbol(),OP_SELL,Amount1,Bid,3,stoploss,takeprofit,"EA Order",0,0,clrBlue);
if(ticket<1)
{
Print("Debug",GetLastError());
}
else
Print("Order successfully");
}
//+------------------------------------------------------------------+
{
points = MarketInfo("GOLD",MODE_POINT);                           //
}
//+------------------------------------------------------------------+
void RunTest()
{
Comment("");                                                      // clear the chart comment when you remove the indicator
}
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
{
if(Digits%2==1) sprd/=10;                                        // convert points to pips
return(rates_total);
}
//+------------------------------------------------------------------+
void GetSymbolPoints()
{
}
//+------------------------------------------------------------------+
```
385

Hi honest_knave,

"I think I may be unnecessarily confusing you because I'm not entirely sure what you are trying to achieve..."

I am trying to setup a code to trade one or possibly two currencies with a minimal invested amount of about \$300 AUD.

16086

 GrumpyDuckMan: I am trying to setup a code to trade one or possibly two currencies with a minimal invested amount of about \$300 AUD. Which has nothing to do with this thread. You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support. Account Balance * percent/100 = RISK = OrderLots * (|OrderOpenPrice - OrderStopLoss| * DeltaPerLot + CommissionPerLot) (Note OOP-OSL includes the SPREAD, and DeltaPerLot is usually around \$10/pip but it takes account of the exchange rates of the pair vs. your account currency.) Do NOT use TickValue by itself - DeltaPerLot You must normalize lots properly and check against min and max. You must also check FreeMargin to avoid stop out