what is the meaning of Volume[0]<=1? - mql4

how can I know the new candle in mql4 is starting?
what is the volume amount of the starting candle? ( starting candle means candle[0])
which of the following codes is true?
a) volume[0]==0
a) volume[0]<0
b) volume[0]<1
c) volume[0]<=1

It's not a good idea to use Volume[0]
Use this code :
void OnTick()
{
static datetime NewBar = 0;
if(NewBar!=Time[0])
{
//do something...
Newbar = Time[0];
}
}

Related

What is the use for a late local variable?

In Dart, we can declare a local variable without initializing it (and yes, it works with null safety too):
void conditionalInit(bool something) {
int x;
if (something) {
x = 1;
print(x); // OK
}
}
If so, what is the added benefit of late modifier? The only one I can think of is that it silences the error of messy conditions like this:
void conditionalInit(bool something) {
int x;
if (something) {
x = 1;
print(x); // OK
}
if (something) {
print(x); // This only compiles with late declaration
}
}
But that should be avoided anyway.
So is there a legitimate use for local late variables?
Here is one possible use for a local late variable:
import 'dart:async';
Stream<int> countToFive() {
late StreamController<int> controller;
controller = StreamController(
onListen: () {
for (int i = 0; i < 5; i++) {
controller.add(i + 1);
}
controller.close();
},
);
return controller.stream;
}
Future<void> main() async {
await for (final number in countToFive()) {
print(number);
}
}
Because controller is late it is possible to reference controller within the onListen callback passed into the constructor of the StreamController.
I think the main use case is lazy initialization. A late variable will only be evaluated when it is accessed, which can be useful for costly computations which may not be required at runtime.
late is also useful to assign immutable final variables after initialization.
void conditionalInit(bool something) {
late final int x;
if (something) {
x = 1;
print(x); // OK
}
}
}

Problem with a task of printing inward triangle with stars

public class TulosteluaLikeABoss {
public static void tulostaTahtia(int maara) {
// part 1
int i = 0;
while (maara >i) {
System.out.print("*");
i++;
}
System.out.println("");
}
public static void tulostaTyhjaa(int maara) {
// part 1.1
int i = 0;
while (maara > i) {
System.out.print(" ");
i++;
}
}
//something is wrong below
public static void tulostaKolmio(int koko) {
// part 2
int j = koko;
int k = 0;
while (koko >= k) {
tulostaTahtia(k);
tulostaTyhjaa(j);
k++;
j = j-1;
}
}
// from here below is irrelevant
public static void jouluKuusi(int korkeus) {
// part 3
}
public static void main(String[] args) {
// Testit eivät katso main-metodia, voit muutella tätä vapaasti.
tulostaKolmio(5);
System.out.println("---");
jouluKuusi(4);
System.out.println("---");
jouluKuusi(10);
}
}
I'm trying to do a Java basics course and the task is to print an inward triangle using stars *
I got my program to print that, but when I try to submit, I get error message saying: When tried to call method tulostaKolmio(1), wrong amount of lines were printed. expected <1> but was <2>. I'm pretty annoyed by this, since I ran the code using tulostaKolmio(1) and the program printed just 1 line that had 1 star like it was supposed to. If the code looks strange it's because this is a 3 part task and I'm only doing the second part.
tulostaKolmio(1) assigns koko the value of 1. The while loop in the method will run (koko + 1) number of times. During the first run in the loop tulostaTahita(0) gets called (since k=0 right now), altough it will not print any starts at this call it will print a new line because you have that outside the while loop in the tulostaTahita method.
During the second run in the loop, k=1 and thus tulostaTahita(1) is called. This will print another line so in the end you are left with 2 lines (where the first one is empty).
To solve this you want to add an if statement to make sure tulostaTahita only prints a new line when maara is greater than 0.

Fibonacci sequence, public static void xxx

I'm just a very beginner and need for help with Fibonacci sequence. So the problem is that I need to ask a number from the answerer and secondly print the Fibonacci number that fits with the answerer's number? Is the method that I need to use "public static void xxx" loop?
I hope someone understands my bad English and can help me with my problem.
I hope you need it in java:
import java.io.*;
public class Fibonacci{
// your method public static void xxx
public static void fib() throws IOException
{
// take input from user
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
// compute nth fibonacci: your loop
int f1 = 0, f2 = 1;
if(n == 0)
System.out.println(f1);
for(int i=2; i<n; i++)
{
int fi = f1 + f2;
f1 = f2;
f2 = fi;
}
// print your answer
System.out.println(f2);
}
public static void main(Strings args[])
{
// call fib method
fib();
}
}

How do I implement the "game loop" in Erlang?

I want to implement a game loop (that is acting as a server) in Erlang, but I dont know how to deal with the lack of incrementing variables.
What I want to do, described in Java code:
class Game {
int posX, posY;
int wall = 10;
int roof = 20;
public void newPos(x,y) {
if(!collision(x,y)) {
posX = x;
posY = y;
}
}
public boolean collision(x,y) {
if(x == wall || y == roof) {
// The player hit the wall.
return true;
}
return false;
}
public sendStateToClient() {
// Send posX and posY back to client
}
public static void main(String[] args) {
// The game loop
while(true) {
// Send current state to the client
sendStateToClient();
// Some delay here...
}
}
}
If the client moves, then the newPos() function is called. This function changes some coordinate variables if a collision do not occur. The game loop is going on forever and is just sending the current state back to the client so that the client can paint it.
Now I want to implement this logic in Erlang but I dont know where to begin. I can't set the variables posX and posY in the same way as here... My only thaught is some kind of recursive loop where the coordinates is arguments, but I don't know if that is the right way to go either...
Your intuition is correct: a recursive loop with the state as a parameter is the standard Erlang approach.
This concept is often abstracted away by using one of the server behaviors in OTP.
Simple example, may contain errors:
game_loop(X, Y) ->
receive
{moveto, {NewX, NewY}} ->
notifyClient(NewX, NewY),
game_loop(NewX, NewY)
end.

c# drop down list selected count

yesterday i asked one question and got the answer from our friend here, and i ran successfully, also it have one problem with it. "Yester day My question is, when we selecting the drop down list then it should be shown by a label as "1" at very first time, again it'll be increas by selection", this is what the answer i got..,
static int count = 0;
private void bind()
{
ArrayList ar = new ArrayList();
ar.Add("first");
ar.Add("Second");
ar.Add("Third");
ar.Add("Four");
ar.Add("Five");
ar.Add("Six");
ar.Add("Seven");
CCddl.DataSource = ar;
CCddl.DataBind();
}
protected void CCddl_SelectedIndexChanged(object sender, EventArgs e)
{
if (count == 0) count = 1;
Label12.Text = count++.ToString();
}
this code worked, but once the running window getting closed, then it lose the continuation, i mean again application getting run it'll shown again "1". But exactly what i want is, the number continuation should be end when the system day has change.
Try using the Application Settings feature. I added two user settings CountDate and Count in the Project->Property's->Settings and changed your SelectedIndexChangedEvent to
protected void CCddl_SelectedIndexChanged(object sender, EventArgs e)
{
if (count == 0) count = 1;
Label12.Text = count++.ToString();
Properties.Settings.Default.CountDate = DateTime.Now.Date;
Properties.Settings.Default.Count = count;
Properties.Settings.Default.Save();
}
And right before you call your Bind Method during your form initialization put something like this.
if(Properties.Settings.Default.CountDate.Date != DateTime.Now.Date)
{
Properties.Settings.Default.Count = 0;
Properties.Settings.Default.CountDate = DateTime.Now.Date;
Properties.Settings.Default.Save();
}
else
count = Properties.Settings.Default.Count;
bind();
Added the Property Settings Image
You should somehow store the value in a database or something. With the date value. Then when the datechanges you just reset the value.

Resources