How to make a function to count (add) return 1 value every hour? MQL4 - mql4

I have a normal loop,where im trying to make dynamic the variable "counter"
int counter;
for ( double i=0; i<counter; i++)
{
What i want to do
};
and then when I run "what I want to do" the "counter = 0". I reset the counter and im looking to add a 1 value to the counter every hour.
I hope you can understand to help me.
Thanks!!

Related

Uncaught Error: RangeError (index): Index out of range: index should be less than 6: 6

hi folks in newbie in programming what is missing in my code
void main(){
print(fib(5));
}
int fib(int n){
List<int> table = List<int>.filled(n+1,0,growable:true);
table[1] = 1;
for(var i = 0; i<=n; i++){
table[i+1] +=table[i];
table[i+2] +=table[i];
}
return table[n];
}
You table is a list with n+1 spots.
Then you have a variable i that runs from 0 to n.
And you access the list for the spots i, i+1, i+2.
But if i reaches n at some point in the loop, that becomes n, n+1, n+2.
And your table has not enough spots to have an n+2. So you are trying to write to it and it just isn't there. So you get an error.
The easiest way to fix it might be to start with a larger list. But you should check your algorithm, too. You are calculating fibonacci values for two instances, even after you already know the value for fib(n). That is not totally wrong, but certainly a waste. The algorithm should only calculate what you ask it to.

mql4 iLowest() giving the wrong candle ID?

I am trying to get the lowest candle ID inside for loop
Use case:
Step 1: i am using for loop to check candle ID of the candle on which the indicator is visible most recently, and then break the loop
Step 2: i am using iLowest() to get the candle ID of the bar having the lowest value out of 5 ,
Step3 : using the candle id (from step 2) to get low value of that candle and then calculate the SL for that candle.
But i am getting wrong ID of candle in Step 2.
please have a look at the below screenshot, the comment of bar should be 74 but it shows 135
Here is my code :
for(int i=0;i<1000;i++)
{
double btt1= iCustom(NULL,0,"Arrows",0,i);
double btt2= iCustom(NULL,0,"Arrows",1,i);
if(btt1!=EMPTY_VALUE)
{
if(Digits==5|| Digits==3)
{
baar =iLowest(NULL,0,MODE_LOW,5+i,i);
lowestb = Low[baar];
stoploss = lowestb- 20*Point*10;
Comment("value of i : ",i," value of baar : " , baar );
ObjectCreate(chart_ID,name,OBJ_LABEL,sub_window,0,0);
ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,xx1x);
ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,yy1y);
ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
ObjectSetString(chart_ID,name,OBJPROP_TEXT, stoploss );
ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clrRed);
ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
break;
}
}
}
What am i doing wrong ?
Change it to :
baar =iLowest(NULL,0,MODE_LOW,5,i);
Because the 4th parameter of the iLowest function counts the number of bars that you want to analyze starting from the counter i (the last parameter).

Google spreadsheet script for insert new row based on value of cell

Spreadsheet data looks like this
function myFunction()
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh = ss.getSheetByName('Active Listeners');
sh.insertRowBefore(15551)
}
As i have large range of rows that could be work on. If the value of the range matches with "Apr 9" then insert row before to that. Could anyone help me to get that.
A 'for loop' to cycle through your rows from the bottom would almost do the trick. The loop inserts a row after each row specified by i. Keep in mind you'll need a different solution if your Apr 9 column is formatted as a date. This works for plain text only. You can select the column and change to plain text with "Format > Number > Plain Text" on the menu.
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh = ss.getSheetByName('Active Listeners');
//var shlen = sh.getDataRange().getLastRow(); //returns integer last row
var shlen = Browser.inputBox("Enter Last Row of Preferred Range", Browser.Buttons.OK_CANCEL);
var ecell = sh.getActiveCell().getA1Notation();
You may need a different dataRange (below), I've just grabbed the parameters of data in your whole sheet (above), then grabbed a range specified in A1 notation of "A1:B[number reference of bottom row]" The modification may be that you need "B1:C" + [shlen] or whichever other range.
if (shlen >= 1) {
var dataRange = sh.getRange("A1:A" + shlen).getValues();
for (var i = shlen; i > 0; i--) {
var row = dataRange[i-1];
if (row[0] == "Apr 9") {
sh.insertRowAfter(i-1)
}
}}
}
Someone more knowledgeable than me can pitch in if they have a better answer, but my only solution (which should be ok if it's a one-of) would be to just repeat the script a few times, starting at the row of your choice each time. Select cell A1 and then press "control (or command) + down arrow". It will take you to the first gap, which should be where the previous script ended. Remember the row number you're up to and plug that in the input box when you run the script again. Might take a few iterations but you'll get there.
If this process is going to be done repeatedly then best of luck in finding a solution :)

Average of textfields depending on how many textfield are "used"

Little explication: I have an app with 5 textfields, i already got the code to make the avaerage of them. Using floates and giving a variable to each textfield.so, the adding of the value of all the textfield /5 (divided per 5)
My problem is that when a textfield is leaved emptty, its not goona be /5, if user fill in only 4 cells it will be/4 and so on.
Question: how to divide the adding of cells depending in how many cells have content?
I was tryng with textfield.text.length > 0 in an if. But i dont get it
Thanks, hope i was clear.
You could check each textfield and see if the text is NULL or blank (#"")
Use an int to keep track of the number of textfields that have a value.
For example:
int counter = 0;
float total = 0.0;
if([textfield1.text length] > 0)
{
counter++;
float thisValue = [textfield1.text floatValue];
total = total + thisValue;
}
repeat this for all 5 textfields and then divide your total by the counter variable.
You could include the if statement in a loop if you are going to vary the number of text fields or to reduce the amount of coding you do.
EDIT I have changed my answer based on the good suggestions of other to use text.length
try to count the number of used textfields by increasing a number every time you read out a textfield that has valid text in it and divide the result by that number. (logically the "number" should be initialized as 0)

Adding +1 to a variable on click of a button adding the wrong number

I am very new to Objective-c and probably really easy to solve but couldnt find an answer anywhere....
I am trying to add +1 to a variable every time the user clicks on the button but instead of adding +1 it adds +4
- (IBAction)addNewSet:(UIButton *)sender {
NSLog(#"%i",_sliderTag);
_sliderTag += 1;
NSLog(#"ADD NEW %i",_sliderTag);
}
_sliderTag is already an NSInteger:
#property (nonatomic,assign) NSInteger* sliderTag;
The first NSLog prints 0 and the 2nd after the add is performed prints 4. Could anyone explain why? It is meant to print 0 the first one, as the point of this variable is to be a counter for setting tags.
Sounds like _sliderTag is a pointer to a type whose size is 4 bytes. Adding 1 to a pointer increments it by the size of the type it points to. Here are two examples that illustrate the difference:
NSInteger foo = 0;
foo += 1;
NSLog(#"result: foo = %d", foo); // result: foo = 1
NSInteger *bar = 0; // note the '*'
bar += 1;
NSLog(#"result: bar = %d", bar); // result: bar = 4
first, make sure _sliderTag is an int or Integer or int and not Integer* or int*, second, dont print it with %i, but with %d

Resources