Why my OrderSend function returns a price higher than the candle high price? - mql4

I'm trying to write an Ea with 2 moving averages, and I want it to send an order when they cross.
Sell orders seem fine, but for Buy orders in 1-min chart, the Ask price which I use to send the order is not in the candle price range. Actually I did Print("Ask=",Ask) right before my OrderEntry function and right after OrderSend(). They are equal to some price way above the candle-[High] and previous candle-[close]
But when I try higher time frames, it get closer to the candle and in daily time frame, the Ask price for orders would be in the candle range (High-Low). Does anybody know why this is happening?
void CheckForMaTrade(){
double PreviousFast = iMA(NULL,0,FastMaPeriod,FastMaShift,FastMaMethod,FastMaAppliedTo,2);
double CurrentFast = iMA(NULL,0,FastMaPeriod,FastMaShift,FastMaMethod,FastMaAppliedTo,1);
double PreviousSlow = iMA(NULL,0,SlowMaPeriod,SlowMaShift,SlowMaMethod,SlowMaAppliedTo,2);
double CurrentSlow = iMA(NULL,0,SlowMaPeriod,SlowMaShift,SlowMaMethod,SlowMaAppliedTo,1);
if(PreviousFast<PreviousSlow && CurrentFast>CurrentSlow)
OrderEntry(0);
if(PreviousFast>PreviousSlow && CurrentFast<CurrentSlow)
OrderEntry(1);
}
void OrderEntry(int direction){
if(direction == 0){
double bsl=0;
double btp=0;
if(StopLoss != 0)
bsl = Ask-(StopLoss*pips);
if(TakeProfit != 0)
btp = Ask+(TakeProfit*pips);
if(OpenOrdersThisPair(Symbol()) < 10 )
OrderSend(NULL,OP_BUY,LotSize,Ask,0,bsl,btp,NULL,MagicNumber,0,Gold);
}
enter image description here

In MT4, the candles are drawn by BID prices only. ASK prices are not taken into consideration. So it is possible that Ask > highest bid.

Related

What are the UI colors for the YouTube superchat tiers?

I'm currently doing some work with the Youtube Live Streaming Api - more specifically the live chat messages API. Its all working fine for now but my main problem is with superchats and superstickers.
https://developers.google.com/youtube/v3/live/docs/liveChatMessages#snippet.superChatDetails.tier
I'm reffering to this bit in youtube's livechat messages documentation. It addresses that each superchat has a tier variable, and that tier correspond's to a UI color which I will need when designing my UI. The documentation says
The tier is based on the amount of money spent to purchase the message. It also determines the color used to highlight the message in the live chat UI, the maximum message length, and the amount of time that the message is pinned the ticker.
The Super Chat tiers, which also cover Super Stickers, are documented in the YouTube Help Center. (See the expandable section about Super Chat purchase details.) In that list, the tier with the lowest purchase amount is tier 1, the next lowest amount is tier 2, and so forth. The Super Chat tiers, which also cover Super Stickers, are documented in the YouTube Help Center. (See the expandable section about Super Chat purchase details.) In that list, the tier with the lowest purchase amount is tier 1, the next lowest amount is tier 2, and so forth.
So I went ahead to the the Youtube Help Center and the closest thing I can find to it supposedly describing the youtube superchat tiers is this article below:
https://support.google.com/youtube/answer/9178268?visit_id=637544258197433496-560511224&rd=1
But again, this article really doesn't document anything that would be relevant to a developer.
So here is my question exactly. Does anybody out there know where I can find the documentation or if somebody knows what the YouTube Superchat tier levels and UI colors are?
If I were stuck on something like this, I would usually just test it out myself rather than trying to find specific documentation, but that's not really possible here. Since if I were to test every single tier, it would probably cost me hundreds of dollars in test donations.
Extra question:
Can anyone also explain what's going on with the whole authorDetails.sponsor vs the member resource, apparently its deprecated but I'm not sure about the exact situation of that?
I'm also trying to access the authorDetails.sponsor variable but apparently the whole Sponsor resource got deprecated and was changed to the Member resource. But then when I visit the member resource it says you need prior approval to use the members.list method but does that also include the authorDetails.sponsor variable?
Here are the documentation links below:
https://developers.google.com/youtube/v3/docs/members
https://developers.google.com/youtube/v3/live/docs/liveChatMessages#authorDetails.isChatSponsor
https://developers.google.com/youtube/v3/live/docs/sponsors
I also noticed that Google does not provide documentation on this (even though the Super Chat API docs mention it is documented.)
I've found this chart to be a useful starting point: https://www.midiaresearch.com/storage/uploads/blog/images/2017/02/Screen-Shot-2017-02-09-at-09.50.17.png
In case that image is not available in the future, here are the values:
Amount Range
Color
Time Displayed (in Ticker)
Max Characters
$1.00 - $1.99
Blue
0s
0
$2.00 - $4.99
Light blue
0s
50
$5.00 - $9.99
Green
2m
150
$10.00 - $19.99
Yellow
5m
200
$20.00 - $49.99
Orange
10m
225
$50.00 - $99.99
Magenta
30m
250
$100.00 - $199.99
Red
1hr
270
$200.00 - $299.99
Red
2hr
290
$300.00 - $399.99
Red
3hr
310
$400.00 - $499.99
Red
4hr
330
$500.00+
Red
5hr
350
The Super Chat API docs mention:
In that list, the tier with the lowest purchase amount is tier 1, the next lowest amount is tier 2, and so forth.
It's probably safe to assume that there are 11 tiers for Super Chats.
edit: I wrote some code to calculate the colors for each amount. I verified that these colors are correct. Feel free to re-use it:
/**
* Calculate the colors for a given super chat amount.
* Returns the background color [0], the header color (darkened) [1],
* and the text color [2].
* #param {string|number} amount
* #returns {[string, string, string]}
*/
const getSuperChatColors = (amount) => {
if (typeof amount === 'string') {
amount = parseFloat(amount.replace(/[^\d.-]/g, ''))
}
if (amount >= 1 && amount <= 1.99) {
return ['#1565C0', '#1565C0', '#FFFFFF']
} else if (amount >= 2 && amount <= 4.99) {
return ['#00E5FF', '#00B8D4', '#000000']
} else if (amount >= 5 && amount <= 9.99) {
return ['#0F9D58', '#0A8043', '#000000']
} else if (amount >= 10 && amount <= 19.99) {
return ['#FFCA28', '#FFB300', '#000000']
} else if (amount >= 20 && amount <= 49.99) {
return ['#F57C00', '#E65100', '#FFFFFF']
} else if (amount >= 50 && amount <= 99.99) {
return ['#E91E63', '#C2185B', '#FFFFFF']
} else if (amount >= 100 && amount <= 199.99) {
return ['#E62117', '#D00000', '#FFFFFF']
} else if (amount >= 200 && amount <= 299.99) {
return ['#E62117', '#D00000', '#FFFFFF']
} else if (amount >= 300 && amount <= 399.99) {
return ['#E62117', '#D00000', '#FFFFFF']
} else if (amount >= 400 && amount <= 499.99) {
return ['#E62117', '#D00000', '#FFFFFF']
} else if (amount >= 500) {
return ['#E62117', '#D00000', '#FFFFFF']
} else {
console.error('Invalid amount for super chat', amount)
return ['#1565C0', '#1565C0', '#FFFFFF']
}
}
Usage:
const [bgColor, headerColor, textColor] = getSuperChatColors('$100.00')
// or
const [bgColor, headerColor, textColor] = getSuperChatColors(60)
// or
const [bgColor, headerColor, textColor] = getSuperChatColors('$1')
// or
const [bgColor, headerColor, textColor] = getSuperChatColors('20')

How to handle weight conversions

I'm currently facing an issue converting between metrics and imperial weights when working with gym equipment. So here in the UK we work with weights in Kilo's where they can increment by 1.25, but overseas i.e. US the weights are measured in pounds and can increment by 0.5.
Handling this isn't an issue, the issue arises when I use the formula to convert between kilo, pounds and vice versa the values are way off. For example a standard UK barbell is 20KG and a US barbell is 45lbs, but when i use the Measurement class to convert it will spit out 44.0925. I already know to convert kilo to pounds you have to multiply it by 2.205 but this is just one example and other values are just as way off.
I've already thought of some other possible solutions one being having an array of possible values in kilos and another that will hold a possible values in pounds but this feels hacky and also wouldn't work since users can input their values into a textfield, which may be an invalid value.
Just curious to see/know if anyone has tackled switching between weight conversion before especially with gym equipment.
I have achieved this by keeping what user has selected option is like it is pound or kg
enum WeightUnitConverted:String {
case kg = "kg"
case pounds = "pound"
case none = ""
}
var weightUnitConvertedValue: WeightUnitConverted = WeightUnitConverted.kg
You have to change this weightUnitConvertedValue whenever the user changes the measurement type. before that you can convert the values
like this I have MVVM
self.viewModel.updateWeightUnit(string: self.weightUnit[selectedRow]) // Like kg or pound, So self.viewModel.weightUnit = "kg"
self.viewModel.updateWeight(string: self.viewModel.convertWeightValues())
self.txtWeight.text = self.viewModel.weight
self.viewModel.weightUnitConvertedValue = WeightEntryViewModel.WeightUnitConverted(rawValue: self.viewModel.weightUnit)!
Here is convertWeightValues()
func convertWeightValues() -> String {
// We need to convert to pounds
if weightUnit.lowercased() == "pound" && weightUnitConvertedValue == .kg {
let punds = convertKGtoPounds()
return punds > 0 ? punds.asNumber : ""
} else if weightUnit.lowercased() == "kg" && weightUnitConvertedValue == .pounds {
// We need to convert to KG
let kg = convertPoundsToKG()
return kg > 0 ? kg.asNumber : ""
}
return self.weight //No need to change so return current weight
}
I know this is a bit confusing for you to implement someone's code Please ask me whatever query you have

How to count how many bars back when closing price crossed and close above certain moving average to known swing low and swing high?

I need to get dynamic bar count using moving average to find swing low and swing high. Please check screenshot for better understanding Thanks in advance
https://imgur.com/OQGy239
double mafast = iMA(NULL,0,15,0,MODE_SMA,PRICE_CLOSE,1);
double maslow = iMA(NULL,0,30,0,MODE_SMA,PRICE_CLOSE,1);
int i=1;
for (i = 1; i<=Bars; i++)
{
if (mafast<maslow || mafast>maslow);
}
int low = iLowest(NULL,0,MODE_LOW,i-1,0);
int high =iHighest(NULL,0,MODE_HIGH,i-1,0);
Print(Low[low]);
Print(High[high]);
}
actual 'Bars' function is getting value for entire chart but i need that should be quantify based on Moving Average price close above or below with strong move

Calculate Percentage when Button is Pressed Apple Watch

I was wondering how I will be able to calculate percentage using Swift. I connected my Buttons to add, subtract, and multiply but I don't know how to code for percentage. I want the app to add the percentage when the 10%, 15%, or 18% is pressed. Thanks
func calculateTip(cost: Double, rateOf rate: Double)->Double
{
return (rate/100) * cost
}
rate is whatever percentage they want. So let's say I want to tip 10%. When the function is called, the 10 is converted to a decimal; rate/100, then multiplying with the item cost will give me the tip amount.
So var grandTotal: Double = cost + calculateTip(cost: cost, rateOf: 10)

Get y-value of points along the generated line graph in Highcharts

I have two series of data--one consists of (Date, Rating), and the other is a list of events that happened on specific dates. The ultimate goal is to use the first series of data to construct a line graph to show how the rating has changed over time, which I've done successfully:
I now need to plot the second set of data using the dates as x-values (different dates than the first set), but want them to show up on the line--meaning I need to get the y-value of what that date would be if it were in the first set. I hope I explained that clearly; let me know if it's confusing.
I forgot I knew how to do algebra.
function getYValue(dataset, date){
//gets rating estimate for closest surrounding dates using algebraic fun-times
var point_1, point_2;
for (j = 0; j < dataset.length; j++){
if (dataset[j][0] > date) {
point_1 = dataset[j-1];
point_2 = dataset[j];
break;
}
}
var slope = (point_2[1] - point_1[1]) / (point_2[0] - point_1[0]);
var rating = slope * (date - point_2[0]) + point_2[1];
return rating;
}

Resources